Opening and Closing Multiple Forms

Tyecom

Well-known member
Joined
Aug 8, 2007
Messages
78
Programming Experience
Beginner
I have an application that has multiple forms. The "main" form within this application can be accessed from other forms. However, each time this "main" form is accessed throughout the application, a "new" instance is created, resulting in multiple instances of this form being open.

I would like to have "only" one instance of this form open at one time. If it is currently opened, I would like it to be brought to the forefront, instead of opening a new instance.

Any suggestion would be greatly appreciated.
 
You can use the default form instance instead of creating new instances yourself, see How to: Access a Form
 
Well you could try:

VB.NET:
Public Sub CheckIfMainFormIsOpen()
 If My.Application.OpenForms("frmMain") Is Nothing Then
           'make new form here
            Dim frmTemp = new frmMain
            frmMain.Show()
 Else
            My.Application.OpenForms("frmMain").Activate()
 End If
End Sub
 
Back
Top