Find Coordinates for point on screen?

非 Y 不嫁゛ 提交于 2019-12-04 14:04:48

Each control hs PointToFoo methods for conversion. Note that you should call this from the parent of the object who's location you want:

Point scrPos = this.PointToScreen(panel1.Location);

Alternatively, you can get the panel's screen coordinates with:

Point scrPos = panel1.PointToScreen(new Point(0,0));

Note that the above two examples could gve different result due to the border-size of the panel.

If you are using the graphics object for the form by calling this.CreateGraphics() within the form, then the coordinates used when you draw the rectangle should be exactly the same as those returned by the click event on the form.

Do you know what coordinates your pointer is in? You can get the coordinates for your window with a call to GetWindowRect() and subtract the top/left from your mouse cursor to get client coordinates.

I seem to remember there being a function to do that for you in fact, but it's been some time since I dabbled in custom GUI controls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!