• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

finding a running instance of a form in vb.net

Hi,
  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()
  addbook_new.Show()

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.....

Regards
Manish



0
manish_prajapati
Asked:
manish_prajapati
1 Solution
 
ampapaCommented:
Can't you just use the visible property of the form to identify if it's visible?

If frmAddBook.visble then exit sub ...
0
 
GrahamSkanRetiredCommented:
There is a VB.Net area. The answers you get here are likely to be biased towards non-.Net visual basic.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
    frmaddbook.show

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 ICON...it 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
0
 
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
            frmAB.Show()
        ElseIf frmAB.WindowState = FormWindowState.Minimized Then
            frmAB.WindowState = FormWindowState.Normal
        End If
        frmAB.Focus()
    End Sub

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

End Class

~IM
0
 
manish_prajapatiAuthor Commented:
Thanks, It is working

Manish
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now