|
-
Jun 8th, 2004, 01:05 PM
#1
Thread Starter
Frenzied Member
Is an Instance of a form "open"
Hello All,
I'm back again with yet another small question...
How can I tell if an instance of one of my forms is already open? I didn't see any kind of "status" property...
For the sake of simplicity in answering, let's assume my form instance is called MyForm and was initiated at the start of my application...
VB Code:
Public MyForm as New frmMyForm
I just need to know if I have opened it (MyForm.Show) or not...
Thanks in advance,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Jun 8th, 2004, 08:42 PM
#2
Lively Member
like this? if not, sorry...
VB Code:
Dim f As Form
For Each f In Me.MdiChildren
If f.Text.Equals("Form2") Then
f.Select()
Exit Sub
End If
Next
f = New Form2()
f.Show()
f.MdiParent = Me
-
Jun 9th, 2004, 04:11 AM
#3
Hyperactive Member
Hi, Squirrelly
If you are sure your form was declared and you only want to know if it is displayed, perhaps you can use something like this:
If MyForm.Visible = True Then
MsgBox("Visible")
End If
Form.Show is the same of Form.Visible=True, and Form.Hide is the same of Form.Visible=False
If it's possible the Form was been closed you need to check that, but, if it's not possible, it should be sufficient....I think and hope
Live long and prosper (Mr. Spock)
-
Jun 9th, 2004, 12:06 PM
#4
Thread Starter
Frenzied Member
Alan,
Thanks for the reply, but I'm not sure if this would work for me because I'm using a Tab/Panel senario for my form display (it's really quite neat actually).
Alextyx,
Here to save the day again I suppose... As I told Alan, I'm using a Tab/Panel senario to display my forms... I'll have to do a little testing to see if switching tabs actually makes the forms or panels visible... I think it would be the panels, but the panels, as you probably know are just the parents for my forms, so this may still work.... I'll just have to try 
Thanks again,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Jun 9th, 2004, 12:07 PM
#5
Thread Starter
Frenzied Member
Man Alextyx, you make me feel like a slacker with my mere 615 posts since 01 and you having over 100 since March 04...
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Jun 9th, 2004, 01:53 PM
#6
You can use a mutex to do this:
VB Code:
Private blnout As Boolean
Private objMut As New System.Threading.Mutex(True, "frmProgress", blnout)
Private Sub frmProgressbar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Create a mutex to see if there is already an instance of my app running
If blnOut = False Then
Me.Close()
End If
End Sub
Private Sub frmProgressbar_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
objMut.Close()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|