title: Pass-through mouse events to parent control
body: <p>Environment: .NET Framework 2.0, VS 2008.</p>
  
  <p>I am trying to create a subclass of certain .NET controls (label, panel) that will pass through certain mouse events (<code>MouseDown</code>, <code>MouseMove</code>, <code>MouseUp</code>) to its parent control (or alternatively to the top-level form). I can do this by creating handlers for these events in instances of the standard controls, e.g.:</p>
  
  <pre><code>public class TheForm : Form
  {
      private Label theLabel;
  
      private void InitializeComponent()
      {
          theLabel = new Label();
          theLabel.MouseDown += new MouseEventHandler(theLabel_MouseDown);
      }
  
      private void theLabel_MouseDown(object sender, MouseEventArgs e)
      {
          int xTrans = e.X + this.Location.X;
          int yTrans = e.Y + this.Location.Y;
          MouseEventArgs eTrans = new MouseEventArgs(e.Button, e.Clicks, xTrans, yTrans, e.Delta);
          this.OnMouseDown(eTrans);
      }
  }
  </code></pre>
  
  <p>I cannot move the event handler into a subclass of the control, because the methods that raise the events in the parent control are protected and I don't have a qualifier for the parent control:</p>
  
  <blockquote>
    <p><em>Cannot access protected member <code>System.Windows.Forms.Control.OnMouseDown(System.Windows.Forms.MouseEventArgs)</code> via a qualifier of type <code>System.Windows.Forms.Control</code>; the qualifier must be of type <code>TheProject.NoCaptureLabel</code> (or derived from it).</em></p>
  </blockquote>
  
  <p>I am looking into overriding the <code>WndProc</code> method of the control in my sub-class, but hopefully someone can give me a cleaner solution.</p>