Can I convert Page to World coordinates

  • Thread starter phil cunningham
  • Start date
P

phil cunningham

I am new to C# and GDI+ so I may have missed a simple way of doing this.

I am trying to use the mouse to pick object up by seeing if the mouse position is Inside the object.

However, I am using the Transform method as follows

float scale=2;
Matrix x = new Matrix();
x.Scale(shift,shift);
g.Transform=x;
pl.Draw(g);


The objects appear twice the size on screen but the mouse position is in the Page system.
How can I transform the mouse position into World coordinates so that I can check it against the real objects


Thanks in advance for any help you can offer
Phil
 
J

Jay B. Harlow [MVP - Outlook]

Phil,
Charles Petzold's book "Program Microsoft windows with Microsoft Visual
Basic .NET" from MS Press, also available in a C# version. Has a number of
example on converting mouse coordinates to world coordinates.

I normally have a function that will initialize the Transform for me
consistently for both the Paint & the Mouse events.

Once I have a consistent Transform I use Graphics.TransformPoints to convert
to & from Page or World & Device coordinates.

The mouse is actually in Device coordinates.

I don't have a sample readily available right now, post if you would like
one.

Hope this helps
Jay


I am new to C# and GDI+ so I may have missed a simple way of doing this.

I am trying to use the mouse to pick object up by seeing if the mouse
position is Inside the object.

However, I am using the Transform method as follows

float scale=2;
Matrix x = new Matrix();
x.Scale(shift,shift);
g.Transform=x;
pl.Draw(g);


The objects appear twice the size on screen but the mouse position is in the
Page system.
How can I transform the mouse position into World coordinates so that I can
check it against the real objects


Thanks in advance for any help you can offer
Phil
 
P

phil cunningham

dear jay

thanks for the reply


I think I've got something working - my problem is the Objects are measured
in Metres and the device units are mm and Mouse is in pixels but it seems to
make sense.


If you have an example this may help a lot

Many thanks
Phil
 

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