Toolbar in a MDI Application

  • Thread starter Thread starter Ellis Yu
  • Start date Start date
E

Ellis Yu

Dear all,

I want to have a toolbar in the main (central) form of an MDI
application. All child forms have 5 common buttons for specific jobs like
SAVE, NEW etc. So when the user is in the child form1 and press the toolbar
button SAVE in the toolbar of main form, then the program will save the data
of child form 1only. Generally the buttons of the toolbar will do the job of
the child form which has the focus (activation) and when there is no child
form open then probably they will be disable. Please help. Thanks.

Best Rdgs
Ellis
 
The ActiveMdiChild of the MDI form tells you which is the active MDI child
form. I would recomend to define an interface like IMDIChildWindow with
methods CanSave, Save, etc. so the MDI Parent can query or invoke those
methods implemented by MDI child windows.

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
Thanks for your help. But I'm still don't understand how to use
interface for invoking the action for different child windows. Would you
please kindly give me some sample code for this? Many thanks.
 
Public Interface IMDIChild
Function CanSave() As Boolean
End Interface

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
....
#End Region

Implements IMDIChild
Public Function CanSave() As Boolean Implements IMDIChild.CanSave
Return True
End Function

End Class

Public Class Form2
Inherits System.Windows.Forms.Form
Implements IMDIChild

#Region " Windows Form Designer generated code "
....
#End Region

Public Function CanSave() As Boolean Implements IMDIChild.CanSave
Return False
End Function

End Class

Public Class MDIForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
....
#End Region

Private Sub MDIForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim f As Form

f = New Form1
f.MdiParent = Me
f.Show()

f = New Form2
f.MdiParent = Me
f.Show()

End Sub

Private Sub MDIForm_MdiChildActivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.MdiChildActivate

Dim frm As Form
Dim objIMDIChild As IMDIChild

frm = Me.ActiveMdiChild

Me.Text = "Can not save"

If Not (frm Is Nothing) Then
If TypeOf frm Is IMDIChild Then
objIMDIChild = DirectCast(frm, IMDIChild)
If objIMDIChild.CanSave Then
Me.Text = "Can save"
End If
End If
End If

End Sub

End Class
--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
Back
Top