Get Position of cursor on panel with scrollbars

前端 未结 2 2114
迷失自我
迷失自我 2020-12-21 06:23

I\'ve build a simple program (so far) that has a large panel as the \"WorkArea\" of the program. I draw a grid onto it, have some functionality that snaps my cursor to clos

2条回答
  •  庸人自扰
    2020-12-21 07:21

    WinForms:

    The method Control.PointToClient lets you convert the mouse position relative to the control itself.

    Point point = grid.PointToClient(new Point(e.X, e.Y))
    

    WPF:

    Using Mouse.GetPosition you can get the position of the mouse relative to a specific control:

    Point position = Mouse.GetPosition(grid);
    

提交回复
热议问题