Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to check if form is open

Status
Not open for further replies.

purplehaze1

Programmer
Jul 23, 2003
86
0
0
US
Is there a way to check if form is open?
If so, how to close it.
For example, I have formA & formB.
I want to open formB from FormA if formB is not
open. If it is open, then close it. Thanks.
 
I assume you have already dimmed the form. Once you do that, the form exists in memory; it just isn't visible to the user. However, certain properties of the form are not initialized when you dim it, specifically its position on the screen. So one thing you could do (and I sure hope someone else has something a bit more elegant) is to examine the DesktopBounds of the form. As long as you don't display your form in the topmost left position (0,0), this will work:

Code:
[blue]dim db as System.Drawing.Rectangle = frmMine.DesktopBounds
If db.Y > 0 Then frmMine.Close()[/blue]

In addition to Y, X, Left, and Top are also set to zero. Once you show the form, those properties are most likely non-zero. To be safe, you should test for more than just db.Y = 0.

terpy
 
hi,

i'm developing an MDI application and had the same problem...i'm not sure if i found the best solution, but here it is...

Code:
    Dim fUsuario As frmUsuario

    Private Sub mniUsuario_Click(ByVal sender As 
                        System.Object, 
                        ByVal e As System.EventArgs) 
                Handles mnuUsuario.Click

        If Not fUsuario Is Nothing Then
            fUsuario.Close()
        End If

        fUsuario = New frmUsuario
        fUsuario.MdiParent = Me
        fUsuario.Show()

    End Sub

i hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top