title: How to display/hide a control on mouse hover event
body: <p>I have been developing an application lately, and found myself stuck on a simple but annoying problem.</p>
  
  <p>I would like to make a specific control visible/not visible when I enter its parent, and being able to perform events (e.g.: click) on this control. The problem is, the mouse hover even does not work on the parent when I enter the very control I want to display. This result in a flickering of the control I want to display (mouse hover works -> control is displayed -> mouse hover does not work anymore -> control is hidden -> mouse hover works -> etc).</p>
  
  <p>I have found this "solution" to help me have something "stable".</p>
  
  <pre><code>    // Timer to make the control appearing properly.
      private void Timer_Elapsed(object o, ElapsedEventArgs e)
      {
          try
          {
              ItemToHideDisplay.Visible = true;
              var mousePoint = this.PointToClient(Cursor.Position);
              if (mousePoint.X &gt; this.Width ||
                  mousePoint.X &lt; 0 ||
                  mousePoint.Y &gt; this.Height ||
                  mousePoint.Y &lt; 0)
              {
                  HideDisplayTimer.Stop();
                  ItemToHideDisplay.Visible = false;
                  base.OnMouseLeave(e);
              }
          }
          catch
          {
              // We don't want the application to crash...
          }
      }
  
      protected override void OnMouseEnter(EventArgs e)
      {
          HideDisplayTimer.Start();
          base.OnMouseEnter(e);
      }
  </code></pre>
  
  <p>Basically, when I enter the object, a timer starts and checks every 50ms if the mouse is in the parent. If so, the control is displayed. If not, the timer is stopped and the control hidden.</p>
  
  <p>This works. Yay. But I find this solution very ugly.</p>
  
  <p>So my question is: is there another approach, another solution more beautiful than this one?</p>
  
  <p>Tell me if I am not clear enough :)</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT: Hey I think I have found it myself!</p>
  
  <p>The trick is to override OnMouseLeave of the parent control with this:</p>
  
  <pre><code>    protected override void OnMouseLeave(EventArgs e)
      {
          var mousePoint = this.PointToClient(Cursor.Position);
          if (mousePoint.X &gt; this.Width ||
  mousePoint.X &lt; 0 ||
  mousePoint.Y &gt; this.Height ||
  mousePoint.Y &lt; 0)
          {
              base.OnMouseLeave(e);
          }
      }
  </code></pre>
  
  <p>This way, when entering the control I have displayed (entering the parent control), the mouse leave event is not triggered! 
  It works!</p>
  
  <p>Thanks for your answers. You can continue to post your ideas I guess, because I don't see a lot of solutions out there on the internet :)</p>