Solved

finding a running instance of a form in vb.net

Posted on 2004-10-26
353 Views
Last Modified: 2012-05-05
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
Question by:manish_prajapati
    6 Comments
     
    LVL 8

    Expert Comment

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

    If frmAddBook.visble then exit sub ...
    0
     
    LVL 76

    Expert Comment

    by:GrahamSkan
    There is a VB.Net area. The answers you get here are likely to be biased towards non-.Net visual basic.
    0
     
    LVL 26

    Expert Comment

    by:EDDYKT
    0
     

    Author Comment

    by:manish_prajapati
    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
     
    LVL 85

    Accepted Solution

    by:
    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
     

    Author Comment

    by:manish_prajapati
    Thanks, It is working

    Manish
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT Security CISA, CISSP & CISM Certification

    Master the advanced techniques required to protect network resources from external threats with the IT Cyber Security bundle. Built around industry best-practice guidelines, the IT Cyber Security bundle consists of three in-depth courses.

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now