title: Dynamically create multiple button and assign single click and double click comand
body: <p>I created multiple button dynamically inside a panel based on multiple click on add button. Each button deletes When I click on it.
  I want each button to delete when I single click on it, and say hello when I double click. Thank you.</p>
  
  <p>I have tried using this code to delete which works fine, but I cannot figure how to assign seperate code to display hello when I double click or right click on it without affecting delete aspect of it.</p>
  
  <pre><code>Private Sub btnDynamic_Click(ByVal sender As Object, ByVal e As EventArgs)
      'Reference the Button which was clicked.
      Dim button As Button = CType(sender, Button)
  
      'Determine the Index of the Button.
      Dim index As Integer = Integer.Parse(button.Name.Split("_")(1))
  
      'Find the TextBox using Index and remove it.
      FlowLayoutPanel1.Controls.Remove(FlowLayoutPanel1.Controls.Find(("btnDynamic_" &amp; index), True)(0))
      'Remove the Button.
      FlowLayoutPanel1.Controls.Remove(button)
      'Rearranging the Location controls.
      For Each btn As Button In FlowLayoutPanel1.Controls.OfType(Of Button)()
          Dim controlIndex As Integer = Integer.Parse(btn.Name.Split("_")(1))
          If (controlIndex &gt; index) Then
              Dim btn1 As Button = CType(FlowLayoutPanel1.Controls.Find(("btnDynamic_" &amp; controlIndex), True)(0), Button)
              btn1.Top = (btn.Top - 25)
              'txt.Top = (txt.Top - 25)
          End If
      Next
  
  End Sub
  </code></pre>
  
  <p>Here is the create button code:</p>
  
  <pre><code>Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
      If TextBox1.Text = "" Then
          Exit Sub
      End If
      Dim count As Integer = Form2.FlowLayoutPanel2.Controls.OfType(Of Button).ToList.Count
      Dim button As Button = New Button
      button.Size = New System.Drawing.Size(28, 21)
      button.Name = "btnDynamic_" &amp; (count + 1)
      button.Text = TextBox1.Text
      AddHandler button.Click, AddressOf Me.button_click
      Form2.FlowLayoutPanel2.Controls.Add(button)
  End Sub
  </code></pre>