Opening a Single Instance of MDI Child form Using VB.NET
-
I am creating an MDI applicalion using VB.NET and I need to know how to restrict opening only one instance of each child form. Currently everytime I click on a child form it opens a new instance of it. If an instance of a particular child form is open and I click to open again it shouldn't let me. Your HELP is greatly appreciated.
-
I am creating an MDI applicalion using VB.NET and I need to know how to restrict opening only one instance of each child form. Currently everytime I click on a child form it opens a new instance of it. If an instance of a particular child form is open and I click to open again it shouldn't let me. Your HELP is greatly appreciated.
Hi. I'm not sure I understand what you mean. In your MDI application, are you clicking a menu item to instantiate a child form? If that's the case, then it should be simple in your parent form to maintain a private variable that can hold the child form. In the menu item code to open the child form, check if the private variable is
nothing
; if it is, set it to a new instance of your child form. If it isn't, then don't create a new child form instance, just use theActivate()
method of the child form in the private variable to bring it to front. Something like this:...
Private _childForm as MyChildFormClass = nothing
...
Private Sub OpenMyChildForm()
If (_childForm Is Nothing) Then
_childForm = new MyChildFormClass()
_childForm.Show()
Else
_childForm.Activate()
End If
End Sub