Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

11. Windows Forms Mouse Handling

11.2 How do I get a mouse cursor position in my control's client coordinates?


Use the Position property of the Cursor class found in the System.Windows.Forms namespace. Here is code that will flag whether the mouse is over button1.

     Point ptCursor = Cursor.Position;
     ptCursor = PointToClient(ptCursor);
     if( button1.Bounds.Contains(ptCursor) )
{
          //mouse over button1
          //....
     }
     else
     {
          //mouse not over button1
          //....
     }