How to know if a form is already open ??

L

LB

How may i do to know if a form is already open ??


In vb6, i use Forms but i don't know how to do this in vbnet.


Thank you!!!
 
O

\(O\)enone

LB said:
How may i do to know if a form is already open ??
In vb6, i use Forms but i don't know how to do this in vbnet.

If you're using VS2005, you can access a collection of open forms using the
Windows.Forms.Application.OpenForms collection, which works like the Forms
collection did in VB6.

If you're using an earlier version is VB.NET, you'll have no option but to
implement your own Forms collection, which can be quite a lot of messing
about...
 
M

Miro

LB said:
How may i do to know if a form is already open ??


In vb6, i use Forms but i don't know how to do this in vbnet.


Thank you!!!

I do this...


'Define the form on the main form so every other form can "see it"
Public Shared fHome As frmHome = Nothing

Then for the button click to open ur form.
In my case its an MDI app.
===
Private Sub tsbHome_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tsbHome.Click

' If the instance still exists... (ie. it's Not Nothing)
If Not IsNothing(fHome) Then
' and if it hasn't been disposed yet
If Not fHome.IsDisposed Then
' then it must already be instantiated - maybe it's
' minimized or hidden behind other forms ?
fHome.BringToFront() ' Optional
Else
' else it has already been disposed, so you can
' instantiate a new form and show it
fHome = New frmHome
fHome.MdiParent = Me
fHome.WindowState = FormWindowState.Maximized
fHome.Show()
End If
Else
' else the form = nothing, so you can safely
' instantiate a new form and show it
fHome = New frmHome
fHome.MdiParent = Me
fHome.WindowState = FormWindowState.Maximized
fHome.Show()
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top