Accessing MDI Forms in VB.NET (preventing multiple instances)
Posted on 2004-11-11
Thanks in advance for any assistance provided!
I have an application which I'm developing in VB.NET which uses forms in an MDI interface. The main form is the container for virtually all other forms in the application with the exception of some help and other simple notification forms.
In the main form, when the user clicks on a "button" to open a child form, I have placed the following code...
If VSOpen = False Then
VSOpen = True
Dim frmView As New ViewStatus
'Set the Parent Form of the Child window.
frmView.MdiParent = Me
'Display the new form.
' Code was removed due to errors.
I created a public shared variable in the main form called VSOpen in this case (boolean) which is set to true when the form is opened initially and is then set to False if the child form is closed. My intention was to check the state of the variable and if it was false, create a new instance of the child form as shown above or if it was true, I intended to "Activate or otherwise show the instance of the form which was already open.
I have tried various ways to do this but keep running into the same issue. Namely, when the child is closed the name of the form (frmView in this case) is disposed of and cannot be reopened. I tried setting the dim statement which declares the form in the code above to a public shared variable and had the same issue.
Any suggestions would be most appreciated. I need to ensure that one and only one instance of each form is open at any time but want to give the users the ability to click on the same controls to open and / or view them as needed (without having to resort to using the "Window - Active Windows" item in the main forms menu bar, which works fine by the way.