title: .NET: How to check if the mouse is in a control?
body: <p>i want to know if the mouse is in a particular control in .NET</p>
  
  <pre><code>private void panel1_MouseLeave(object sender, EventArgs e)
  {
     if (MouseIsInControl((Control)sender)
        return; //the mouse didn't leave, don't fire a MouseLeave event
  
     ...
  }
  
  public Boolean MouseIsInControl(Control control)
  {
      //return (control.Bounds.Contains(MousePosition));
      return control.Bounds.Contains(control.PointToClient(MousePosition))
  }
  </code></pre>
  
  <p>But i need someone to fiddle with the four different coordinate systems to make it work<a href="https://stackoverflow.com/questions/347439/custom-controls-in-c-sharp-windows-forms-mouse-event-question">.</a></p>
  
  <h2>Related questions</h2>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/986529/how-to-detect-if-the-mouse-is-inside-the-whole-form-and-child-controls-in-c">How to detect if the mouse is inside the whole form and child controls in C#?</a> (entire form)</li>
  <li><a href="https://stackoverflow.com/questions/347439/custom-controls-in-c-sharp-windows-forms-mouse-event-question">Custom controls in C# Windows Forms mouse event question</a> (control with label inside)</li>
  </ul>