about mdi child ?

code hunter

Member
Joined
Sep 7, 2006
Messages
7
Programming Experience
Beginner
hi friends:)

what to do if i don't want mdichild to be opened inside mdi form more than once?:confused:

my mdi form is form1
my mdichild form is form2

i tried this code but it's not working fine
-----------------------------------------
VB.NET:
Dim child As New Form2
If Form2 Is Nothing Orelse Form2.IsDisposed Then
'The form has either not been created or has been closed so create a new one.
child.MdiParent = Me 'Edit
child.Show()
Else
'Activate the existing form.
child.Activate()
End If
-----------------------------------------
is there any wrong in my way?
i really need your help

best regards
 
Last edited by a moderator:
when dealing with MDI applications, i tend to have a module level variable of the child form, then in a menu item or a toolbar button i'll keep making instances of the child form:

VB.NET:
Private ChildForm As Form2 'Form2 in your case, i always rename all my forms to help me keep them straight

Private Sub mnuNewChild_Click (...) Handles mnuNewChild.Click
  ChildForm = New Form2
  ChildForm.MdiParent = Me
  ChildForm.Show
End Sub

by doing it this way, everytime that menu item is clicked a new copy of the form is shown and it doesnt affect any of the other open ones either
 
Back
Top