Check Control Information by Mouse Hovers

2011-06-28


When you move your mouse point on the screen, there are some information can be shown when you hover a control.

How can you do it? In this case we are going to use Windows From, not Web From.

This sample is from a similar case on internet:

There is a panel, then put some children controls, and the children controls are nested by one inside the other, for example, put 3 levels of nesting.  We want to show the children control’s name which the controls located at the mouse point place when mouse hovers somewhere.

The sample code is like:

private Control GetControlAtPoint(Control ctl, Point location)
{ 
   Control retV = ctl;
 
   foreach (Control child in ctl.Controls)
   { 
     Rectangle rec = child.RectangleToScreen(ctl.DisplayRectangle); 

     if (rec.Contains(location))
           retV = GetControlAtPoint(child, location); 
   }
 
   return retval; 
} 

private void panel1_MouseMove(object sender, MouseEventArgs e)
{ 
   Control ctl = GetControlAtPoint(panel1, panel1.PointToScreen(e.Location)); 

   Console.WriteLine(ctl.Name); 
}