title: Click event handlering from form to usercontrol
body: <p>Hey guys I wanna ask how forward event handler for click on dynamic generate buttons. This buttons I generate to flowlayout panel in Form1.cs
  I generate usercontrol &quot;btnMini.cs&quot; where I have it 2 button.
  How can i forward click event for these buttons from Form1 to UserControl - &quot;btnMini.cs&quot; ?
  I wanna after click on button forward and get messagebox.show where is &quot;Parent name of button&quot; and other show me &quot;button name&quot;. How can I do it from Form1?</p>
  <pre><code>Button btn = (Button)sender;
  MessageBox.Show(&quot;button name: &quot; + btn.Name + &quot;, Parent name control: &quot; + btn.Parent.Name);
  </code></pre>
  <p>I try this but I dont know how do it when I need create MessageBox.Show in Form1 after Clicking....
  Thank you for advice. I am little hopeless how do it :/ so thanks very body for tips.
  Code:</p>
  <pre class="lang-cs prettyprint-override"><code>public partial class btnMini : UserControl
  {
      public btnMini()
      {
          InitializeComponent();
      }
      
      [Browsable(true)]
      [Category(&quot;ActionClick&quot;)]
      [Description(&quot;Invoke when user clicks on button&quot;)]
      public event EventHandler ButtonClick;//ok
     
      private void TestingClicks(object sender, EventArgs e)
      {
          ButtonClick?.Invoke(sender, e);
      }
      
      public void OnClick(object sender, EventArgs e)
      {
          TestingClicks(sender, e);           
      }
  }
  
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
      
      #region variables
      
      private int counter = 1;
      private btnMini btnM = new btnMini();
      private List&lt;Control&gt; control = new List&lt;Control&gt;();
      
      //public event EventHandler ClickTest;
      
      #endregion
  
      //Using this method I adding userControl to list
      private void button1_Click(object sender, EventArgs e)
      {
          //Button btn = (Button)sender;
          //MessageBox.Show(&quot;Click btn: &quot; + btn.Name + &quot;, Parent name control: &quot; + btn.Parent.Name); //Here I tried do this for get Name of parent and button UserControl - btnMini.cs
  
          btnM = new btnMini();
          btnM.Name = &quot;btn_&quot; + counter;
          btnM.Click += (s, ev) =&gt;
          {
              Button b = (Button)sender;
              //string parent = button?.Parent?.Name;
              MessageBox.Show(b.Name.ToString());
          };
          counter++;
          control.Add(btnM);
      }
      
      //method for adding UserControl from List.
      private void button2_Click(object sender, EventArgs e)
      {
          foreach (var b in control)
          {
              this.flowLayoutPanel1.Controls.Add(b);
          }
      }
  }
  </code></pre>
  <p><img src="https://i.stack.imgur.com/Rm48l.png" alt="enter image description here" /></p>