How to heck if Form is closed?

L

Lore Leunoeg

Hello

I want to open one Form from another form. But only if it isn't already
open. I tried this (code below) but to click the close [x] Button of a form
doesn't seem to set the referencing variables to Nothing.

Private frm As Form2
Private Sub btnShowForm_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShowForm.Click
If (frm Is Nothing) Then
frm = New Form2()
frm.Show()
End If
End Sub

So how can I check if the Form2 is already there or closed again?

Thank you
Sincerely
Lore
 
G

Guest

I want to open one Form from another form. But only if it isn't already open.

1. In a module, declare a pubic variable like
Public MyForm2 as Form2 = Nothing
An alternative to a module is a class with a shared public variable.

2. In Form2's closing event, set MyForm2 to nothing.

3. When you want to run form2, do something like this:
If MyForm2 is Nothing then
MyForm2 = new Form2
MyForm2.Show
else
' maybe if minimized, restore it (MyForm2.FormWindowState)
'maybe give focus somewhere (MyForm2.ActiveControl)
' maybe do nothing
endif
 
H

Herfried K. Wagner [MVP]

Lore Leunoeg said:
I want to open one Form from another form. But only if it isn't already
open. [...]
So how can I check if the Form2 is already there or closed again?

\\\
Private m_ReportForm As ReportForm
..
..
..
If m_ReportForm Is Nothing OrElse m_ReportForm.IsDisposed Then
m_ReportForm = New ReportForm()
m_ReportForm.Show()
Else
m_ReportForm.Activate()
End If
///
 

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