title: How to pass multiple button click event from child to parent in c#
body: <ul>
  <li>I have 18 buttons on the child form &quot;Control Test&quot; which send event to the parent form</li>
  <li>Out of 18 buttons, 14 are  ON and OFF functionality, making 7 pairs as in the picture</li>
  <li>The problem is raising the event for each button, it causes very long and messy code, both in the child and the parent form,</li>
  <li>Is there any less complex way to do it? like I have done with the menu.</li>
  </ul>
  <p>Child Form:<br />
  <a href="https://i.stack.imgur.com/DiYLz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DiYLz.png" alt="enter image description here" /></a></p>
  <p>Child Form:</p>
  <pre class="lang-cs prettyprint-override"><code>// B Plus Relay On Button
  public event EventHandler BPRElayOnBtnClicked;
  protected virtual void WhenBPRelayOnBtnClicked(EventArgs e)
  {
      BPRElayOnBtnClicked.Invoke(this, e);
  }
  private void BPRelayOn_btn_Click(object sender, EventArgs e)
  {
      WhenBPRelayOnBtnClicked(e);
  }
  
      // B Plus Relay OFF Button
  public event EventHandler BPRElayOffBtnClicked; 
  protected virtual void WhenBPRelayOffBtnClicked(EventArgs e)
  {
      BPRElayOnBtnClicked.Invoke(this, e);
  }
  private void BPRelayOff_btn_Click(object sender, EventArgs e)
  {
      WhenBPRelayOffBtnClicked(e);
  }
  
  
  
  // B Minus Relay ON Button
  public event EventHandler BMRElayOnBtnClicked;
  protected virtual void WhenBMRelayOnBtnClicked(EventArgs e)
  {
      BMRElayOnBtnClicked.Invoke(this, e);
  }
  
  private void BMRelayOn_btn_Click(object sender, EventArgs e)
  {
      WhenBMRelayOnBtnClicked(e);
  }
  
  // B Minus Relay OFF Button
  public event EventHandler BMRElayOffBtnClicked;
  protected virtual void WhenBMRelayOffBtnClicked(EventArgs e)
  {
      BMRElayOffBtnClicked.Invoke(this, e);
  }
  
  private void BMRelayOff_btn_Click(object sender, EventArgs e)
  {
      WhenBMRelayOffBtnClicked(e);
  }
  ...... //event for each button
  
  </code></pre>
  <p>Parent Form:</p>
  <pre class="lang-cs prettyprint-override"><code>private void viewToolStripMenuItem_Click(object sender, EventArgs e)
  {
      ToolStripMenuItem menu = sender as ToolStripMenuItem;
  
      switch (menu.Name)
      {
                 
          case &quot;controlTestToolStripMenuItem&quot;:
              if (Application.OpenForms[&quot;CtrlTest&quot;] is CtrlTest ctrlTest)
              {
                  ctrlTest.Focus();
                  return;
              }
              ctrlTest = new CtrlTest();
              ctrlTest.BPRElayOnBtnClicked += CtrlTest_BPRElayOnBtnClicked;
              ctrlTest.BPRElayOffBtnClicked += CtrlTest_BPRElayOffBtnClicked;
              ctrlTest.BMRElayOnBtnClicked += CtrlTest_BMRElayOnBtnClicked;
              ctrlTest.BMRElayOffBtnClicked += CtrlTest_BMRElayOffBtnClicked;
              ctrlTest.PreRElayOnBtnClicked += CtrlTest_PreRElayOnBtnClicked;
              ctrlTest.PreRElayOffBtnClicked += CtrlTest_PreRElayOffBtnClicked;
              ctrlTest.MdiParent = this;
              ctrlTest.Show();
              break;
              .........//Other menus ...
          default:
              break;
  private void CtrlTest_BPRElayOnBtnClicked(object sender, EventArgs e)
  {
      //Do something here
  }
  private void CtrlTest_BPRElayOffBtnClicked(object sender, EventArgs e)
  {
      //Do something here
  }
  private void CtrlTest_BMRElayOnBtnClicked(object sender, EventArgs e)
  {
      //Do something here
  }
  private void CtrlTest_BMRElayOffBtnClicked(object sender, EventArgs e)
  {
      //Do something here
  }
  </code></pre>