Dustin Brooks
Dustin Brooks

Reputation: 2591

How to get mouse position over a certain control

Windows Form
I'm using the DragOver event on a layoutpanel and the DragEventArgs returns the X/Y coordinates of the mouse in relation to the screen. I know there is a function to translate this in to the position of the mouse over the control, but I'm having difficulty locating it.

Upvotes: 9

Views: 15098

Answers (2)

Antikhippe
Antikhippe

Reputation: 6685

Try using PointToClient method to compute the location of the specified screen point into client coordinates.

private void DragDrop(object sender, DragEventArgs e)
{
        Point point = this.PointToClient(new Point(e.X, e.Y));
        // then use point.X and point.Y instead of e.X and e.Y
}

Upvotes: 0

mqp
mqp

Reputation: 72005

Try Control.PointToClient and Control.PointToScreen.

Upvotes: 19

Related Questions