473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to heck if Form is closed?

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
Nov 21 '05 #1
2 936
> 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

Nov 21 '05 #2
"Lore Leunoeg" <lo*********@gmx.net> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
7
by: VM | last post by:
Hi, Is it possible to open always only one instance of a MDIChild form? Say, if form A is already opened, just give it the focus. I tried declaring theMDIChild forms as private members of the...
5
by: rob willaar | last post by:
Hi, How can i check is a form is disposed in framework 1.1 In framework 2.0 i can check Form.IsDisposed to check if a user closed the form
7
by: Xero | last post by:
How do you detect whether a form has been closed or not? Thanks. -- Xero http://www.chezjeff.net My personal web portal
2
by: Geoff Jones | last post by:
Hiya Supposing a form has been created as follows: Dim form1 As New Form How can I check to see if the form has been closed i.e. by clicking on the cross in the top right of the form. ...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
9
by: Anil Gupte | last post by:
I have a MDI Parent Child set of forms FormContainer --MDIParent FormStart --MDIChild FormMain-->MDIChild FormSliceInfo-->MDIChild I use the following in the beginning of FomrContainer ...
5
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.