Question

The thing is I have some graphics shown in a form, rectangle for example, and I want to capture when the point gets over thees fields. So I Thoght I try to find the corrrdinates for thees rectangles, but as thay are the coords in the form it dose not match the ones with the mouse location.

So I wonder is there a way to find what coord on the screen a Point has on the screen and not in the form or controller?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top