title: vb.net control button in popup
body: <p>I'm new to programming and I need help with something really basic..</p>
  
  <p>I have a form with a datagridview and an "insert" button that opens a popup window (new form). This popup contains labels and textboxes, and 2 buttons (insert &amp; cancel). How do you add event handlers to the buttons inside the popup? For example, if the user clicks "Cancel", the popup should close.</p>
  
  <p>Here's the code I have so far:</p>
  
  <p>Public Sub InsertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertButton.Click</p>
  
  <pre><code>    Dim insertPopup As New Form
      insertPopup.Size = New System.Drawing.Size(300, 400)
      insertPopup.StartPosition = FormStartPosition.CenterScreen
      insertPopup.Show()
  
      Dim acceptButton As New Button
      Dim cancelButton As New Button
  
      acceptButton.Location = New System.Drawing.Point(100, 325)
      acceptButton.Text = "Insert"
      acceptButton.Size = New System.Drawing.Size(85, 24)
      acceptButton.TabIndex = 1
  
      cancelButton.Location = New System.Drawing.Point(190, 325)
      cancelButton.Text = "Cancel"
      cancelButton.Size = New System.Drawing.Size(85, 24)
      cancelButton.TabIndex = 2
  
      insertPopup.Controls.Add(acceptButton)
      insertPopup.Controls.Add(cancelButton)
  
  End Sub
  </code></pre>
  
  <p>Thanks for your help.</p>