title: Remove single event handler from a user control
body: <p>Say I have two user controls and I want to remove an event handler from one instance of the control.</p>
  
  <p>To illustrate I've just made it a button as user control:</p>
  
  <pre><code>public partial class SuperButton : UserControl
  {
  public SuperButton()
  {
      InitializeComponent();
  }
  
  private void button1_MouseEnter(object sender, EventArgs e)
  {
      button1.BackColor = Color.CadetBlue;
  }
  
  private void button1_MouseLeave(object sender, EventArgs e)
  {
      button1.BackColor = Color.Gainsboro;
  }
  }
  </code></pre>
  
  <p><strong>I've added two super buttons to the form and I want to disable the MouseEnter event firing for SuperButton2.</strong></p>
  
  <pre><code>public partial class Form1 : Form
  {
  public Form1()
  {
      InitializeComponent();
      superButton2.RemoveEvents&lt;SuperButton&gt;("EventMouseEnter");
  }
  }
  
  public static class EventExtension
  {
  public static void RemoveEvents&lt;T&gt;(this Control target, string Event)
  {
      FieldInfo f1 = typeof(Control).GetField(Event, BindingFlags.Static | BindingFlags.NonPublic);
      object obj = f1.GetValue(target.CastTo&lt;T&gt;());
      PropertyInfo pi = target.CastTo&lt;T&gt;().GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
      EventHandlerList list = (EventHandlerList)pi.GetValue(target.CastTo&lt;T&gt;(), null);
      list.RemoveHandler(obj, list[obj]);
  }
  
  public static T CastTo&lt;T&gt;(this object objectToCast)
  {
      return (T)objectToCast;
  }
  }
  </code></pre>
  
  <p>The code runs but it doesn't work - the MouseEnter and Leave events still fire. I'm looking to do something like this:</p>
  
  <p>superButton2.MouseEnter -= xyz.MouseEnter;</p>
  
  <p><strong>Update:</strong> Read this comments questions...</p>