prevent multiple Instances of a form

  • Thread starter Thread starter Poohface
  • Start date Start date
P

Poohface

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
 
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
 
Poohface said:
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/[email protected]>
 
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
 
Poohface said:
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".
 
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
 

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

Back
Top