Live Chat Icon For mobile
Live Chat Icon

How do I get a mouse cursor position in my control’s client coordinates

Platform: WinForms| Category: Mouse Handling

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
		//....
	}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.