ToolBar Click with MDI form

  • Thread starter Thread starter MadCrazyNewbie
  • Start date Start date
M

MadCrazyNewbie

Hey Group,

Im using the following code in a ToolBar button to load up a form in my main
MDI container:

Case e.Button Is Me.tbbPasswordLists
Dim LoadPasswordLists As New frmMainMenuPasswords()
LoadPasswordLists.MdiParent = Me 'the MainForm
LoadPasswordLists.WindowState = FormWindowState.Maximized
LoadPasswordLists.Show()

Only problem is that if a user clicks on the toolbar button over and over
again it justs keeps opening the child form over and over again.

How would i get it to check to see if the form was already open, if it was
bring it to the front, if it isn`t open, load it?

Many Thanks
MCN
 
Simon,

Cycle through your MDIForm.MdiChildren (it's a collection of forms that have
the MDIParent property set to your mdi form).

then if the form exists set the focus. here is some code to help you out.

Public Function FormAlreadyExists(ByRef ChildType As System.Type) As Form

Dim ctl As System.Windows.Forms.Form

Dim retVal As Form

For Each ctl In Me.MdiChildren

If (ctl.GetType() Is ChildType) Then

retVal = ctl

Exit For

End If

Next

ctl = Nothing

Return retVal

End Function
 
Hey CJ hows it going?

Sorry you have confused me a little now:(

Have you any links for reading??

Many Thanks
Si

CJ Taylor said:
Simon,

Cycle through your MDIForm.MdiChildren (it's a collection of forms that have
the MDIParent property set to your mdi form).

then if the form exists set the focus. here is some code to help you out.

Public Function FormAlreadyExists(ByRef ChildType As System.Type) As Form
Dim ctl As System.Windows.Forms.Form
Dim retVal As Form
For Each ctl In Me.MdiChildren
If (ctl.GetType() Is ChildType) Then
retVal = ctl
Exit For
End If
Next
ctl = Nothing
Return retVal
End Function
 
Simon,

Sorry I don't. I wrote this function. Sorry the implementation code would
be

Dim tForm as System.Windows.Forms.Form

tForm = FormAlreadyExists(gettype(myForm))

if not tForm is Nothing then
tForm.Focus()
else
myForm.Show()
end if
 
Back
Top