|
-
Jan 11th, 2004, 08:41 PM
#1
Thread Starter
Fanatic Member
Toolbar with save button
Dear All,
My Toolbar has a button "SAVE", it has click event, when the click event occur it will call a function called "DoSave()" ..my problem is I have more than 10 forms with data being inputed, i want my users to be able to click a save button on the toolbar and it will save the data on any active form. how to deal with this?
many thanks
Regards
Winanjaya
-
Jan 11th, 2004, 11:10 PM
#2
You can use the MDIParent form's ActiveMdiChild property to reference the currently active MdiChild. Technically if you know that the form has a DoSave method you can just do:
DirectCast(Me.ActiveMdiChild, Object).DoSave()
Although that is very bad form and Option Sctrict wont like it. The more proper way to do this is to give all of the forms that will have this functionality something in common. In this case a common interface. Then you create your common interface with any members that they will need and implement it in all forms that you want to have that functionality. Then you can check for and/or cast to that common interface to access the functionality and it will all be type safe or strongly typed.
VB Code:
'add the common interface
Public Interface ICommon
Sub DoSave()
End Interface
'implement it in the mdichildren
Public Class Form1
Inherits System.Windows.Forms.Form
Implements ICommon
Public Sub DoSave() Implements ICommon.DoSave
MsgBox(Me.Name)
End Sub
'then use it in the MdiParent
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'check that active form has interface
If TypeOf Me.ActiveMdiChild Is ICommon Then
'cast to interface and use it
DirectCast(Me.ActiveMdiChild, ICommon).DoSave()
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|