Check MdiChild is open or not?

mythinky

Member
Joined
Jun 4, 2004
Messages
20
Programming Experience
1-3
Hi, guys, i have an VB.NET app, the problem is every time i click on the sub menubar, it will create a new mdichild form. What i want is if it's already created, then just active it. Otherwise, just create a new one. How to solve this problem? Please provide the code.
My currently code is:
Dim objForm as New Form()
objForm.MdiParent = Me
objForm.Show()

Thanks in advance...
 
VB.NET:
'First declare the form variable as a class member
Private objForm as frmMdiChild1

'the code for the MenuItem click event handler:
Private Sub mniOpen_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles mniOpen.Click
    'use the short-ciruiting orElse operator to avoid error
    'when checking IsDisposed, in case it hasn't been created yet 
    If objForm Is Nothing OrElse objForm.IsDisposed Then _
      objForm = New frmMdiChild1()
    'always set MdiParent and show the form
    'won't do anything if already active
    objForm.MdiParent = Me
    objForm.Show()
End Sub
 
Back
Top