|
|
Title | Manage MDI children using a toolbar |
Keywords | MDI, background, draw, MDIForm, child |
Categories | Graphics, Tips and Tricks |
|
|
Place a toolbar on the MDI form. When you create a new child form, make a button for it. When the user clicks the button, find the child form and bring it to the top of the child stack.
|
|
' If this is the New button, make a new child form.
' Otherwise find the child form and bring it to
' the top of the pile.
Private Sub Toolbar1_ButtonClick(ByVal Button As _
MSComctlLib.Button)
Dim btn As Button
Dim frm As Form
If Button.Key = "New" Then
Set frm = New Form1
frm.Show
Set btn = Toolbar1.Buttons.Add(, , , tbrDefault, 2)
m_MaxIndex = m_MaxIndex + 1
frm.Caption = "Form " & Format$(m_MaxIndex)
btn.ToolTipText = frm.Caption
Else
' Find this window.
For Each frm In Forms
If frm.Caption = Button.ToolTipText Then Exit _
For
Next frm
If Not (frm Is Nothing) Then
frm.WindowState = vbNormal
frm.Show
End If
End If
End Sub
|
|
When a child form unloads, it should search the toolbar to find its button and remove it.
|
|
' Remove this form's button.
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
For i = 2 To MDIForm1.Toolbar1.Buttons.Count - 1
If MDIForm1.Toolbar1.Buttons(i).ToolTipText = _
Caption Then Exit For
Next i
If i < MDIForm1.Toolbar1.Buttons.Count Then
MDIForm1.Toolbar1.Buttons.Remove i
End If
End Sub
|
|
|
|
|
|