Results 1 to 4 of 4

Thread: one instance of form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    india
    Posts
    108

    one instance of form

    in vb.net we can show the child form as:

    dim frm as new childform1
    frm.show

    but if we call these line more than one then it will creates a another instance on childform....

    how can we stop user to create more than 1 instance of a form...meanz only one form will exist

    anand
    Anand Thakur

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Something like this should work for you .
    VB Code:
    1. Dim frm As Form
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.  
    5.         If frm Is Nothing Then
    6.             frm = New Form
    7.             frm.Show()
    8.         Else
    9.             Exit Sub
    10.         End If
    11.  
    12.     End Sub

  3. #3
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    or this:

    VB Code:
    1. Dim blnFound As Boolean = False
    2.                 Dim frmChild As Form
    3.                 For Each frmChild In Me.MdiChildren
    4.                     If TypeOf frmChild Is frmSuperApproval Then
    5.                         frmChild.Focus()
    6.                         blnFound = True
    7.                         Exit For
    8.                     End If
    9.                 Next
    10.                 'If form not already loaded then load form
    11.                 If blnFound = False Then
    12.                     Dim frmSuperApproval1 As New frmSuperApproval()
    13.                     frmSuperApproval1.MdiParent = Me
    14.                     frmSuperApproval1.Show()
    15.                 End If
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Your code is more efficient than mine . Cool .

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