Trouble with pixels

J

Jaap Bos

In VB2005 I use a rectangle (50,50,910,600) into which to display my
graphics.
After graphing my X-Y data I want to do some measurements on that curve
using a crosshair cursor.

So I a made a MouseDoubleClick event with the following code:

Dim position as Point
position=Control.MousePostion
tijd=position.X
height=position.Y

Now it seems that the height is in screencoordinates, not in
graphicscoordinates, e.g. if I doubleclick on the topline of my rectangle I
get height=76 pixels, instead of 50 pixels (the difference of 26 pixels is
the height of the forms titelbar). This difference of course becomes larger
with a form that is not maximized.

Now I can live with that by always using a maximized screen and substracting
26 from the position.Y, but that does not seems not very elegant.

Is there a better way to get the coordinates in a graphics window in
graphicscoordinates?
 
L

Larry Lard

Jaap said:
Is there a better way to get the coordinates in a graphics window in
graphicscoordinates?

Control.PointToClient and Control.PointToScreen will convert back and
forth for you.
 
J

Jaap Bos

Larry Lard said:
Control.PointToClient and Control.PointToScreen will convert back and
forth for you.

Thank you Larry, you solved my problem!

As an afterthought, I find, as a newbie, that it is rather difficult to get
a grasp of the possibilities of using graphics in VB2005.
I read the Michael Halvorson Step by Step book and watched the Microsoft
online video's.
After this I have some knowledge about VB-programming, but I still know nil
about graphics, apart from drawing a line or a rectangle.
Befor I asked my question I looked into the Help-index of VB but really
could not find the answer that you gave me.
Can you point me to a (not to advanced :) ) book or online material on
VB-graphics?

Thanks again,

Jaap
 
L

Larry Lard

Jaap said:
Thank you Larry, you solved my problem!

As an afterthought, I find, as a newbie, that it is rather difficult to get
a grasp of the possibilities of using graphics in VB2005.
I read the Michael Halvorson Step by Step book and watched the Microsoft
online video's.
After this I have some knowledge about VB-programming, but I still know nil
about graphics, apart from drawing a line or a rectangle.
Befor I asked my question I looked into the Help-index of VB but really
could not find the answer that you gave me.
Can you point me to a (not to advanced :) ) book or online material on
VB-graphics?

Bob Powell's excellent website is my first port of call whenever I have
a graphics issue:

<http://www.bobpowell.net/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top