views:

779

answers:

3

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?

A: 

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.

Fiona Holder
A: 

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.

Jon Cage
+4  A: 

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.

Henk Holterman
Excellent!now I can usePoint scrPos = menuItemForm.PointToScreen(mSize.Location);to locate the point where the rectangle mSize is located and there by detect mouse-over for this rectangle.