title: Winform - determine if mouse has left user control
body: <p>I am struggling with something that I think should be easily (ish).  I have a windows form and a flowgridlayout panel at the bottom of the form.  Inside this form I dynamically populate it with X number of User Controls.  The controls are all the same type.</p>
  
  <p>The goal is when the user hoovers the mouse over the user control it opens another form and positions it where the mouse is.  When mouse leaves the form the opened form disappears.</p>
  
  <p>This almost works great.  The problem is when the User Control has anything like a label or text box inside it.  It is considered to have left the UC so the form disappears.</p>
  
  <p>My thought was then to use the X and Y to tell if it is inside the UC but I can not figure this out.</p>
  
  <p>Can I ask:</p>
  
  <p>1)  What is the best approach to this?
  2)  How can I code it, as the UC's are dynamic I can not know exactly where they will be.</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I am trying to figure out the mouse pointers but not getting there.  The code below is within the UC SmallTagBox_MouseLeave event:</p>
  
  <pre><code>        Point loc = this.Location;
          Point p = this.PointToScreen(this.Location);
          Point p2 = this.PointToScreen(this.Parent.Location);
  
          Point ms = MousePosition;
          Rectangle screenBounds = new Rectangle(this.PointToScreen(this.Location), this.Size);
          if (!screenBounds.Contains(ms))
          {
              thw.Close();
              thw = null;
          }
  </code></pre>
  
  <ul>
  <li>loc {X = 275 Y = 3} System.Drawing.Point</li>
  <li>p   {X = 808 Y = 908}   System.Drawing.Point</li>
  <li>p   {X = 808 Y = 908}   System.Drawing.Point</li>
  <li>p2  {X = 545 Y = 1542}  System.Drawing.Point</li>
  <li>ms  {X = 574 Y = 914}   System.Drawing.Point</li>
  <li>screenBounds    {X = 808 Y = 908 Width = 62 Height = 29}    System.Drawing.Rectangle</li>
  </ul>
  
  <p>I do not understand how p2 (its parent) can have a greater Y value relative to the screen.</p>