title: how to prevent multiple instances of a form?
body: <p>I am working on a project where i have a home form which has two buttons for login for employee and administrator.after clicking on button login form will open,but i want as soon as login window opens d previous home form must be closed or hide..also there is link on login page for home,but as soon as user click on home link new instance of home form is opening,hnce i want to stop dis multiple opening of the form.i tried close() and hide() but no use....
  code for form1 ie home form;</p>
  
  <pre><code>Public Class Form1
      Inherits System.Windows.Forms.Form
  
  #Region " Windows Form Designer generated code "
  
      Public Sub New()
          MyBase.New()
  
          'This call is required by the Windows Form Designer.
          InitializeComponent()
  
          'Add any initialization after the InitializeComponent() call
  
      End Sub
  
      'Form overrides dispose to clean up the component list.
      Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
          If disposing Then
              If Not (components Is Nothing) Then
                  components.Dispose()
              End If
          End If
          MyBase.Dispose(disposing)
      End Sub
  
      'Required by the Windows Form Designer
      Private components As System.ComponentModel.IContainer
  
      'NOTE: The following procedure is required by the Windows Form Designer
      'It can be modified using the Windows Form Designer.  
      'Do not modify it using the code editor.
      Friend WithEvents Label1 As System.Windows.Forms.Label
      Friend WithEvents Label4 As System.Windows.Forms.Label
      Friend WithEvents Button1 As System.Windows.Forms.Button
      Friend WithEvents Button2 As System.Windows.Forms.Button
      &lt;System.Diagnostics.DebuggerStepThrough()&gt; Private Sub InitializeComponent()
          Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
          Me.Label1 = New System.Windows.Forms.Label
          Me.Label4 = New System.Windows.Forms.Label
          Me.Button1 = New System.Windows.Forms.Button
          Me.Button2 = New System.Windows.Forms.Button
          Me.SuspendLayout()
          '
          'Label1
          '
          Me.Label1.Font = New System.Drawing.Font("Georgia", 12.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
          Me.Label1.Location = New System.Drawing.Point(136, 184)
          Me.Label1.Name = "Label1"
          Me.Label1.Size = New System.Drawing.Size(100, 40)
          Me.Label1.TabIndex = 8
          Me.Label1.Text = "Employee Login"
          '
          'Label4
          '
          Me.Label4.Font = New System.Drawing.Font("Georgia", 12.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
          Me.Label4.Location = New System.Drawing.Point(288, 184)
          Me.Label4.Name = "Label4"
          Me.Label4.Size = New System.Drawing.Size(136, 48)
          Me.Label4.TabIndex = 12
          Me.Label4.Text = "Administrator Login"
          '
          'Button1
          '
          Me.Button1.BackgroundImage = CType(resources.GetObject("Button1.BackgroundImage"), System.Drawing.Image)
          Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
          Me.Button1.Location = New System.Drawing.Point(152, 104)
          Me.Button1.Name = "Button1"
          Me.Button1.Size = New System.Drawing.Size(64, 64)
          Me.Button1.TabIndex = 16
          '
          'Button2
          '
          Me.Button2.BackColor = System.Drawing.Color.Transparent
          Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
          Me.Button2.Image = CType(resources.GetObject("Button2.Image"), System.Drawing.Image)
          Me.Button2.Location = New System.Drawing.Point(312, 104)
          Me.Button2.Name = "Button2"
          Me.Button2.Size = New System.Drawing.Size(64, 64)
          Me.Button2.TabIndex = 17
          '
          'Form1
          '
          Me.AutoScaleBaseSize = New System.Drawing.Size(7, 15)
          Me.BackColor = System.Drawing.Color.White
          Me.ClientSize = New System.Drawing.Size(496, 341)
          Me.Controls.Add(Me.Button2)
          Me.Controls.Add(Me.Button1)
          Me.Controls.Add(Me.Label4)
          Me.Controls.Add(Me.Label1)
          Me.Font = New System.Drawing.Font("Georgia", 9.75!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
          Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
          Me.Name = "Form1"
          Me.Text = "Employee Management System"
          Me.ResumeLayout(False)
  
      End Sub
  
  #End Region
  
  
  
  
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
  
  
      End Sub
  
  
  
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim frmDialogue As New Form5
  
          frmDialogue.ShowDialog()
  
  
      End Sub
  
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
          Dim frmDialogue As New Form7
  
          frmDialogue.ShowDialog()
  
      End Sub
  End Class
  </code></pre>