473,499 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

prevent multiple Instances of a form

ok here is what I'm doing at the moment and its no good:

\\
Dim ThisForm as FormWhatever

Private Sub SomeKindOfClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SomeKindOfClick.Click
If ThisForm Is Nothing Then
ThisForm = New FormWhatever
End If
ThisForm.Show()
End Sub
//

Now the 1st time I click, ThisForm comes up and thats great, if I
click again it sees that ThisForm is something and all is well, I only
get one instance of ThisForm. Now, if I close ThisForm it's dispose
method gets called but ThisForm does not turn into a nothing. It's
still a FormWhatever and when we get to the ThisForm.show part I get
and error that I cannot access a disposed object called FormWhatever.

What is the best way to make it so the user can only launch one
instance of a form, but when they close it, they are able to relaunch
one.

Pls & Thx,
Norst
Nov 21 '05 #1
8 1257
You might try:

If ThisForm Is Nothing orelse ThisForm.IsDisposed then

"Poohface" wrote:
ok here is what I'm doing at the moment and its no good:

\\
Dim ThisForm as FormWhatever

Private Sub SomeKindOfClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SomeKindOfClick.Click
If ThisForm Is Nothing Then
ThisForm = New FormWhatever
End If
ThisForm.Show()
End Sub
//

Now the 1st time I click, ThisForm comes up and thats great, if I
click again it sees that ThisForm is something and all is well, I only
get one instance of ThisForm. Now, if I close ThisForm it's dispose
method gets called but ThisForm does not turn into a nothing. It's
still a FormWhatever and when we get to the ThisForm.show part I get
and error that I cannot access a disposed object called FormWhatever.

What is the best way to make it so the user can only launch one
instance of a form, but when they close it, they are able to relaunch
one.

Pls & Thx,
Norst

Nov 21 '05 #2
ok I got it working with this, but there must be a better way:
(same set up as below with this in click event)
\\
'if its 1st time launching
If Legend Is Nothing Then
Legend = New ColorLegend
Legend.Show()
Exit Sub
End If

'if its launched and open, bring it to the front
If Legend.Visible = True Then
Legend.TopMost = True
Legend.TopMost = False
Exit Sub
End If

'if its been launched and closed
Legend = New ColorLegend
Legend.Show()
//

Any ideas?

Thx,
Norst

On Sat, 23 Apr 2005 18:43:48 -0400, Poohface
<po******@shityerpantsoff.crap> wrote:
ok here is what I'm doing at the moment and its no good:

\\
Dim ThisForm as FormWhatever

Private Sub SomeKindOfClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SomeKindOfClick.Click
If ThisForm Is Nothing Then
ThisForm = New FormWhatever
End If
ThisForm.Show()
End Sub
//

Now the 1st time I click, ThisForm comes up and thats great, if I
click again it sees that ThisForm is something and all is well, I only
get one instance of ThisForm. Now, if I close ThisForm it's dispose
method gets called but ThisForm does not turn into a nothing. It's
still a FormWhatever and when we get to the ThisForm.show part I get
and error that I cannot access a disposed object called FormWhatever.

What is the best way to make it so the user can only launch one
instance of a form, but when they close it, they are able to relaunch
one.

Pls & Thx,
Norst

Nov 21 '05 #3
"Poohface" <po******@shityerpantsoff.crap> schrieb:
Dim ThisForm as FormWhatever

Private Sub SomeKindOfClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SomeKindOfClick.Click
If ThisForm Is Nothing Then
ThisForm = New FormWhatever
End If
ThisForm.Show()
End Sub
//

Now the 1st time I click, ThisForm comes up and thats great, if I
click again it sees that ThisForm is something and all is well, I only
get one instance of ThisForm. Now, if I close ThisForm it's dispose
method gets called but ThisForm does not turn into a nothing.


See:

<URL:http://groups.google.de/groups?selm=eILSwL4CFHA.2072%40TK2MSFTNGP10.phx.gb l>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
ok now that 2 of you.. None of my forms seem to have this IsDisposed
member? Seems to be no such thing? I see it in the documentation but
none of my Forms or Controls for that matter have it? What the deal
with that?

Norst

On Sun, 24 Apr 2005 01:49:25 +0200, "Herfried K. Wagner [MVP]"
<hi***************@gmx.at> wrote:
"Poohface" <po******@shityerpantsoff.crap> schrieb:
Dim ThisForm as FormWhatever

Private Sub SomeKindOfClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SomeKindOfClick.Click
If ThisForm Is Nothing Then
ThisForm = New FormWhatever
End If
ThisForm.Show()
End Sub
//

Now the 1st time I click, ThisForm comes up and thats great, if I
click again it sees that ThisForm is something and all is well, I only
get one instance of ThisForm. Now, if I close ThisForm it's dispose
method gets called but ThisForm does not turn into a nothing.


See:

<URL:http://groups.google.de/groups?selm=eILSwL4CFHA.2072%40TK2MSFTNGP10.phx.gb l>

Nov 21 '05 #5
"Poohface" <po******@shityerpantsoff.crap> schrieb:
ok now that 2 of you.. None of my forms seem to have this IsDisposed
member? Seems to be no such thing? I see it in the documentation but
none of my Forms or Controls for that matter have it? What the deal
with that?


I assume that 'IsDisposed' is marked as an advanced member. You can show
advanced members in the code editor with the "Hide advanced members" option
under "Tools" -> "Options" -> "Text Editor" -> "Basic" -> "General".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6
OMG! I had no idea that was even there!! LOL I've been using VS for
over 3 years! hahaha

Thank you very much, now I'm wondering what else I've missed!

Norst

On Sun, 24 Apr 2005 02:27:13 +0200, "Herfried K. Wagner [MVP]"
<hi***************@gmx.at> wrote:
"Poohface" <po******@shityerpantsoff.crap> schrieb:
ok now that 2 of you.. None of my forms seem to have this IsDisposed
member? Seems to be no such thing? I see it in the documentation but
none of my Forms or Controls for that matter have it? What the deal
with that?


I assume that 'IsDisposed' is marked as an advanced member. You can show
advanced members in the code editor with the "Hide advanced members" option
under "Tools" -> "Options" -> "Text Editor" -> "Basic" -> "General".

Nov 21 '05 #7
If it is not too much trouble, you can probably implement a Singleton Design
Pattern for your form. A Singleton Pattern guarentees only a single instance
of your class. Take a look at:

http://msdn.microsoft.com/library/de...tondespatt.asp

It may be overkill on what your trying to do, but it is a slick way to
guarentee one instance of your form class.

"Poohface" wrote:
ok here is what I'm doing at the moment and its no good:

\\
Dim ThisForm as FormWhatever

Private Sub SomeKindOfClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SomeKindOfClick.Click
If ThisForm Is Nothing Then
ThisForm = New FormWhatever
End If
ThisForm.Show()
End Sub
//

Now the 1st time I click, ThisForm comes up and thats great, if I
click again it sees that ThisForm is something and all is well, I only
get one instance of ThisForm. Now, if I close ThisForm it's dispose
method gets called but ThisForm does not turn into a nothing. It's
still a FormWhatever and when we get to the ThisForm.show part I get
and error that I cannot access a disposed object called FormWhatever.

What is the best way to make it so the user can only launch one
instance of a form, but when they close it, they are able to relaunch
one.

Pls & Thx,
Norst

Nov 21 '05 #8
Yes, this is a much better way to do it. I think the idea of the class
and not the client controling the instances of the class is very slick
indeed. Thank you!

PS- Found a more VB tailored sample of this @
http://www.codeproject.com/Purgatory...n_patterns.asp

Thx again,
Norst

On Sun, 24 Apr 2005 13:41:02 -0700, "rmacias"
<rm*****@newsgroup.nospam> wrote:
If it is not too much trouble, you can probably implement a Singleton Design
Pattern for your form. A Singleton Pattern guarentees only a single instance
of your class. Take a look at:

http://msdn.microsoft.com/library/de...tondespatt.asp

It may be overkill on what your trying to do, but it is a slick way to
guarentee one instance of your form class.

Nov 21 '05 #9

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

Similar topics

1
2663
by: Job Lot | last post by:
How can I prevent multiple instances of MdiChild form? I have a MdiParent form with a DataGrid showing all the clients in the database. User clicks on a row to open MdiChild form which display...
12
3198
by: (Pete Cresswell) | last post by:
I know I can open many instances of a given form, but I've never done it. Now I'm analyzing an application where that seems like just the ticket: Many investment funds, *lots* of data points for...
4
12228
by: logicalfeline | last post by:
How do you prevent multiple instances of a program from running? Cat
2
6307
by: Brian Keating EI9FXB | last post by:
Hello there, What is the best way in c# to prevent multiple instances of my application running at same time on one machine? thanks Brian
11
20867
by: Clark Stevens | last post by:
I just finished a WinForms app in VB.NET. I want to allow the user to be able to run multiple instances of the program like you can with Notepad and Wordpad. The way it is now, once I run the...
4
3815
by: Rich | last post by:
Hello, my app opens a 2nd form (form2) by clicking a button on the first form (form1). I do not want to open form2 in modal form, but I only want one instance of form2 open. So if someone...
2
2460
by: Job Lot | last post by:
How can I prevent multiple instances of a C# windows forms application. VB.NET provides My.Application.StartupNextInstance Event to do this. Is there any C# equivalent as well? Thanks
11
12780
by: Tony K | last post by:
I have a MDI application. On the menu toolstrip child forms are selected from one of the menus. I don't want to play the disable/enable menu item game. I have selected that open forms are added...
5
3294
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
7005
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
7168
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,...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.