Results 1 to 3 of 3

Thread: checking previous instance of form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    5

    checking previous instance of form

    Hello,

    I have a form1,from the context menu i am calling the form2
    The form2 is loaded fine.Once again if i am again accessing
    the context menu clicking.One more copy of form2 is loaded.
    If the previous instance of form2 is loaded and active.
    Then i do not want to load it again.
    How to do this in vb.net.It is easy for me in vb6.




    Thanks and regards
    shawlin

  2. #2
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    many ways -

    Check if the form Is Nothing before (re)loading it. Use the FindWindow API function, Create the form using the singleton design pattern OR simply have an callback to Form1 from Form2 which disables/enables the menuitem when Form2 is loaded/unloaded.

    I think this was discussed in previous threads - do a search

    Cheers

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: checking previous instance of form

    If you want to check for form instances , something like this would work :
    VB Code:
    1. 'put this in the general declaration form
    2. Dim FRM2 As New Form 'or if you have another form replace it here
    3.  
    4.  
    5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal
    6. e As System.EventArgs) Handles Button1.Click
    7.  
    8. If Not FRM2 Is Nothing Then 'allows one instance of the form named Form
    9.             FRM2.Show()
    10.         Else
    11.             FRM2 = Nothing
    12.         End If
    13.  
    14.    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