Results 1 to 6 of 6

Thread: Is an Instance of a form "open"

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    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:
    1. 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?

  2. #2
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    like this? if not, sorry...
    VB Code:
    1. Dim f As Form
    2.       For Each f In Me.MdiChildren
    3.          If f.Text.Equals("Form2") Then
    4.             f.Select()
    5.             Exit Sub
    6.          End If
    7.       Next
    8.       f = New Form2()
    9.       f.Show()
    10.       f.MdiParent = Me

  3. #3
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    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)

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026
    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?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026
    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?

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    You can use a mutex to do this:

    VB Code:
    1. Private blnout As Boolean
    2.     Private objMut As New System.Threading.Mutex(True, "frmProgress", blnout)
    3.  
    4.  
    5.     Private Sub frmProgressbar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         'Create a mutex to see if there is already an instance of my app running
    7.  
    8.  
    9.         If blnOut = False Then
    10.             Me.Close()
    11.  
    12.         End If
    13.     End Sub
    14.  
    15.     Private Sub frmProgressbar_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    16.         objMut.Close()
    17.     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
  •  



Click Here to Expand Forum to Full Width