Results 1 to 2 of 2

Thread: Toolbar with save button

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    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

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 'add the common interface
    2. Public Interface ICommon
    3.     Sub DoSave()
    4. End Interface
    5.  
    6. 'implement it in the mdichildren
    7. Public Class Form1
    8.     Inherits System.Windows.Forms.Form
    9.     Implements ICommon
    10.  
    11.     Public Sub DoSave() Implements ICommon.DoSave
    12.         MsgBox(Me.Name)
    13.     End Sub
    14.  
    15. 'then use it in the MdiParent
    16.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    17.         'check that active form has interface
    18.         If TypeOf Me.ActiveMdiChild Is ICommon Then
    19.             'cast to interface and use it
    20.             DirectCast(Me.ActiveMdiChild, ICommon).DoSave()
    21.         End If
    22.     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
  •  



Click Here to Expand Forum to Full Width