How to get mouse position over a certain control
Asked Answered
C

2

9

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.

Cassation answered 21/1, 2009 at 14:36 Comment(0)
C
19

Try Control.PointToClient and Control.PointToScreen.

Copro answered 21/1, 2009 at 14:38 Comment(3)
This answer could be improved with the code sample being put here instead of a link away.Nonviolence
Well you can feel free to edit it and put that code sample right in.Copro
I haven't figured out what the code should be yet or I would :)Nonviolence
G
0

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
}
Granduncle answered 28/3, 2022 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.