finding a running instance of a form in

  I want to know how i can find an running instance of a form so that i can restrict the user to reopen the same form again.
 Say as a address book is open using this code lines.......

  Dim addbook_new As New frmAddressBook()

if the user again clicks address book link , and if the address book already open , then restrict the user to reopen it. all i want is to find an running instance of an form...

I don't want to use a variable for decision.....

Please reply.....


Who is Participating?
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can do it using a technique similar to this:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private WithEvents frmAB As frmAddBook

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If frmAB Is Nothing Then
            frmAB = New frmAddBook
        ElseIf frmAB.WindowState = FormWindowState.Minimized Then
            frmAB.WindowState = FormWindowState.Normal
        End If
    End Sub

    Private Sub frmAB_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmAB.Closed
        frmAB = Nothing
    End Sub

End Class

Can't you just use the visible property of the form to identify if it's visible?

If frmAddBook.visble then exit sub ...
There is a VB.Net area. The answers you get here are likely to be biased towards non-.Net visual basic.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

manish_prajapatiAuthor Commented:
Hi, There is problem in it.. I am explaining you..

Suppose i take a global declaration as
   dim frmaddbook as new frmaddressbook()

and on clicking address book Icon , i show the form by

when user again clicks the ICON ,I check if frmaddbook.visible=ture and if ture then EXIT SUB.
if user closes the address book form and after then clicks the address book gives a fault that .. frmaddbook instance is diaposed and it couldn't be shown bt .show

I need to find the instance of frmaddbook so that i can check the status whether it is open ,closed....\

manish_prajapatiAuthor Commented:
Thanks, It is working

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.