473,568 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting a custom coordinate system like VB picturebox.Scal e

Does anyone know how to change the the GDI+ coordinate system like you used
to be able to do in VB6 with the picturebox.scal e method. The
picturebox.scal e method took an x,y point defining the upper left corner and
a second x,y point defining the lower right corner.

In VB6 the 0,0 location was the upper left like in GDI+, but I could at
least reset it so I could use it with lat/lons. Basically all I want to do
is be able to use the USA lat/lon coordinates to put a circle at a
particular lat/lon.

I've looked at Graphics.Rotate Transform and graphics.Transl ateTransform, but
they don't seem to do it for me.

-Randy
Nov 20 '05 #1
7 17428
Nak
Hi there,

Have you thought about a simple scaling algorithm to turn your values
into the pixel equivilents? This might be the simplest approach. I wish I
could quote one for you now but I never have been good at maths and it would
require me hunting through zip disks. But I hope the concept helps you as
their isn;t a "scale" method in .NET (That I know of).

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #2
Randy,
I've looked at Graphics.Rotate Transform and graphics.Transl ateTransform, but they don't seem to do it for me. You were close ;-)

You need to use Graphics.Transl ateTransform along with
Graphics.ScaleT ransform.

The trick is to call them in the correct order with the correct parameters.

You need to call TranslateTransf orm to move the origin to the lower left.
You can use 0 & me.ClientRectan gle.Height.

Then you need to call ScaleTransform with 1 & -1 as parameters to flip the y
axis.

Hope this helps
Jay

"Randy Vande Hei" <randyv (at) itol (dot) com> wrote in message
news:uH******** ********@tk2msf tngp13.phx.gbl. .. Does anyone know how to change the the GDI+ coordinate system like you used to be able to do in VB6 with the picturebox.scal e method. The
picturebox.scal e method took an x,y point defining the upper left corner and a second x,y point defining the lower right corner.

In VB6 the 0,0 location was the upper left like in GDI+, but I could at
least reset it so I could use it with lat/lons. Basically all I want to do
is be able to use the USA lat/lon coordinates to put a circle at a
particular lat/lon.

I've looked at Graphics.Rotate Transform and graphics.Transl ateTransform, but they don't seem to do it for me.

-Randy

Nov 20 '05 #3
Nak
Oops, I stand corrected :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #4
"Randy Vande Hei" <randyv (at) itol (dot) com> wrote in message
news:uH******** ********@tk2msf tngp13.phx.gbl. ..
Does anyone know how to change the the GDI+ coordinate system like you used to be able to do in VB6 with the picturebox.scal e method. The
picturebox.scal e method took an x,y point defining the upper left corner and a second x,y point defining the lower right corner.


Well, I sorta missed the old Scale method too so I decided to roll my own
once and for all. IIRC, if you wanted to (predictably) draw arcs in VB.OLD
you
really needed to have "square" canvases so this method always uses the
same scaling factor horizontally and vertically. If you don't want/need that
you
need to slightly change the code so that it calculates and uses 2
scalingfactors:
one for the horizontal scaling and one for the vertical scaling.

Private mWorld2DeviceXf m As New System.Drawing. Drawing2D.Matri x()
Private mDevice2WorldXf m As New System.Drawing. Drawing2D.Matri x()

Public Sub SetScale( _

ByVal xupperleft As Integer, ByVal yupperleft As Integer, _

ByVal xlowerright As Integer, ByVal ylowerright As Integer)

Dim XMirrorFactor As Single = CSng(Sign(xlowe rright - xupperleft))

Dim ScaleFactor As Single

If Me.Size.Width < Me.Size.Height Then 'remember to compensate for
non-square canvas !

ScaleFactor = CSng(Me.Size.Wi dth) / Abs(xlowerright - xupperleft)

Else

ScaleFactor = CSng(Me.Size.He ight) / Abs(yupperleft - ylowerright)

End If

'construct forward matrix (world coord -> device coord)

mWorld2DeviceXf m.Reset()

mWorld2DeviceXf m.Translate( CSng(-xupperleft), CSng(-yupperleft))

mWorld2DeviceXf m.Scale( XMirrorFactor * ScaleFactor, -1! * ScaleFactor,
MatrixOrder.App end)

'also store inverse matrix (device coord -> world coord) for convenience
when hit-testing

If mWorld2DeviceXf m.IsInvertible( ) Then

mDevice2WorldXf m = mWorld2DeviceXf m.Clone()

mDevice2WorldXf m.Invert()

End If

End Sub

Please note that this method is taken from a custom control that derives
from

System.Windows. Forms.Scrollabl eControl. That's why Me.Size is used to
determine the

physical size of the canvas we're drawing on. Your situation may be slightly
different so

take care. Also, try to understand what's going on, it will help you to use
it better.

You can use this method in OnPaint like this:

Protected Overrides Sub OnPaint(ByVal e As
System.Windows. Forms.PaintEven tArgs)

Dim xlowleft As Integer, ylowleft As Integer

Dim xupright As Integer, yupright As Integer

MyBase.OnPaint( e)

'calculate your xlowleft, ylowleft, xupright, yupright

......

Me.SetScale( xlowleft, ylowleft, xupright, yupright)

e.Graphics.Tran sform = mWorld2DeviceXf m

'Draw your stuff on the gr object here

........

End Sub

HTH

eltwo
Nov 20 '05 #5
"Randy Vande Hei" <randyv (at) itol (dot) com> wrote in message
news:uH******** ********@tk2msf tngp13.phx.gbl. ..
Does anyone know how to change the the GDI+ coordinate system like you used to be able to do in VB6 with the picturebox.scal e method. The
picturebox.scal e method took an x,y point defining the upper left corner and a second x,y point defining the lower right corner.


Well, I sorta missed the old Scale method too so I decided to roll my own
once and for all. IIRC, if you wanted to (predictably) draw arcs in VB.OLD
you really needed to have "square" canvases so this method always uses the
same scaling factor horizontally and vertically. If you don't want/need that
you need to slightly change the code so that it calculates and uses 2
scalingfactors: one for the horizontal scaling and one for the vertical
scaling.

Private mWorld2DeviceXf m As New System.Drawing. Drawing2D.Matri x()
Private mDevice2WorldXf m As New System.Drawing. Drawing2D.Matri x()

Public Sub SetScale( _
ByVal xupperleft As Integer, ByVal yupperleft As Integer, _
ByVal xlowerright As Integer, ByVal ylowerright As Integer)

Dim XMirrorFactor As Single = CSng(Sign(xlowe rright - xupperleft))
Dim ScaleFactor As Single

' compensate for non-square canvas
If Me.Size.Width < Me.Size.Height Then
ScaleFactor = CSng(Me.Size.Wi dth) / Abs(xlowerright - xupperleft)
Else
ScaleFactor = CSng(Me.Size.He ight) / Abs(yupperleft - ylowerright)
End If

' construct forward matrix (world coord -> device coord)
mWorld2DeviceXf m.Reset()
mWorld2DeviceXf m.Translate( CSng(-xupperleft), CSng(-yupperleft))
mWorld2DeviceXf m.Scale( XMirrorFactor * ScaleFactor, -1! * ScaleFactor, _
MatrixOrder.App end)

' also store inverse matrix (device coord -> world coord) for
' convenience when hit-testing
If mWorld2DeviceXf m.IsInvertible( ) Then
mDevice2WorldXf m = mWorld2DeviceXf m.Clone()
mDevice2WorldXf m.Invert()
End If

End Sub
Please note that this method is taken from a custom control that derives
from System.Windows. Forms.Scrollabl eControl. That's why Me.Size
is used to determine the physical size of the canvas. Your situation may be
different so take care. So now you can use this method in OnPaint like
this:

Protected Overrides Sub OnPaint( ByVal _
e As System.Windows. Forms.PaintEven tArgs)

Dim xupleft As Integer, yupleft As Integer
Dim xloright As Integer, yloright As Integer

MyBase.OnPaint( e)

' calculate your xupleft, yupleft, xloright, yloright
............... ..............
Me.SetScale( xupleft, yupleft, xloright, yloright)
e.Graphics.Tran sform = mWorld2DeviceXf m

' draw your stuff on the e.Graphics here
............... ...............

End Sub

HTH

eltwo
Nov 20 '05 #6
That is exactly what I was looking for. Thanks.

I used e.graphics.Tran slateTransform (this.ClientRec tangle.Width,
this.ClientRect angle.Height) to get the origin over to the bottom right.
So I now have 0,0 a the bottom right. What I need next is to set the upper
limit of x and y so that my plotting can have the affect of zooming.
Again, the vb scale method used to allow this.

i.e. I'd like to be able to fill the window with my plotting regardless of
what size the window is sized to.

-Randy
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:uC******** ******@tk2msftn gp13.phx.gbl...
Randy,
I've looked at Graphics.Rotate Transform and graphics.Transl ateTransform, but
they don't seem to do it for me.

You were close ;-)

You need to use Graphics.Transl ateTransform along with
Graphics.ScaleT ransform.

The trick is to call them in the correct order with the correct

parameters.
You need to call TranslateTransf orm to move the origin to the lower left.
You can use 0 & me.ClientRectan gle.Height.

Then you need to call ScaleTransform with 1 & -1 as parameters to flip the y axis.

Hope this helps
Jay

"Randy Vande Hei" <randyv (at) itol (dot) com> wrote in message
news:uH******** ********@tk2msf tngp13.phx.gbl. ..
Does anyone know how to change the the GDI+ coordinate system like you

used
to be able to do in VB6 with the picturebox.scal e method. The
picturebox.scal e method took an x,y point defining the upper left corner

and
a second x,y point defining the lower right corner.

In VB6 the 0,0 location was the upper left like in GDI+, but I could at
least reset it so I could use it with lat/lons. Basically all I want to do is be able to use the USA lat/lon coordinates to put a circle at a
particular lat/lon.

I've looked at Graphics.Rotate Transform and graphics.Transl ateTransform,

but
they don't seem to do it for me.

-Randy


Nov 20 '05 #7
Randy,
You use ScaleTransform to 'zoom' also.

I normally use a ratio of this.ClientSize (which is the same as
this.ClientRect angle.Size) to the size of my drawing. To get the drawing to
fit in the window itself.

You can call ScaleTransform twice, once to flip the drawing, then a second
time to zoom the drawing. Order should not matter.

Hope this helps
Jay
"Randy Vande Hei" <randyv (at) itol (dot) com> wrote in message
news:eE******** *****@tk2msftng p13.phx.gbl...
That is exactly what I was looking for. Thanks.

I used e.graphics.Tran slateTransform (this.ClientRec tangle.Width,
this.ClientRect angle.Height) to get the origin over to the bottom right.
So I now have 0,0 a the bottom right. What I need next is to set the upper limit of x and y so that my plotting can have the affect of zooming.
Again, the vb scale method used to allow this.

i.e. I'd like to be able to fill the window with my plotting regardless of what size the window is sized to.

-Randy
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message news:uC******** ******@tk2msftn gp13.phx.gbl...
Randy,
I've looked at Graphics.Rotate Transform and graphics.Transl ateTransform,
but
they don't seem to do it for me. You were close ;-)

You need to use Graphics.Transl ateTransform along with
Graphics.ScaleT ransform.

The trick is to call them in the correct order with the correct

parameters.

You need to call TranslateTransf orm to move the origin to the lower left.
You can use 0 & me.ClientRectan gle.Height.

Then you need to call ScaleTransform with 1 & -1 as parameters to flip the y
axis.

Hope this helps
Jay

"Randy Vande Hei" <randyv (at) itol (dot) com> wrote in message
news:uH******** ********@tk2msf tngp13.phx.gbl. ..
Does anyone know how to change the the GDI+ coordinate system like you used
to be able to do in VB6 with the picturebox.scal e method. The
picturebox.scal e method took an x,y point defining the upper left

corner and
a second x,y point defining the lower right corner.

In VB6 the 0,0 location was the upper left like in GDI+, but I could
at least reset it so I could use it with lat/lons. Basically all I want

to do is be able to use the USA lat/lon coordinates to put a circle at a
particular lat/lon.

I've looked at Graphics.Rotate Transform and

graphics.Transl ateTransform, but
they don't seem to do it for me.

-Randy



Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1913
by: SirPoonga | last post by:
What would you suggest I do for the following problem. I want to make an application (vb.net or c#) that has a picture of a dartboard and you can click on certain cells of the dartboard. I am wondering what the best way to determine where on a dartboard the user clicked. An image map or custom buttons for each cell. if image map how...
0
1247
by: Jacob | last post by:
Hi all, In a VB6 picturebox, I am able to place 0,0 in the lower left (SW) corner by using the Scale method, How do I accomplish this in VB.NET?? Jacob
1
1335
by: K.N.Ranjit | last post by:
Hi to all friends out there.I am presently working in TCS and I am supposed to do the work given to me in line cordinates using VB.net.But over here I face a problem (ie) I want my coordinate (0,0) to start in the lower-left corner of my form instead of the default upper-left corner of the form.If anyone could provide me the solution I would...
0
1631
by: SamSpade | last post by:
I have a usercontrol that contains a picturebox. The user can obtain (creategraphics) a picturebox graphics object and draw on the picturebox. She could do gr.GraphincInit.Millimeter and then draw using millimeters as the measurement. But he would still have to dimension the Picture box using pixels (Clientsize for example). He changes the...
1
1670
by: Ricardo Furtado | last post by:
I've been with a problem for about two months and i've bought books and search the internet for an explanation, and haven't found one. I'm developing a cephalometric software, that needs to capture an image from the scanner, mark the image with dots in order to find distances and angles. Everything is ok except when i try to zoom in/zoom out...
14
3974
by: Roger Withnell | last post by:
How to I find out what size text the browser is set to? Thanks in anticipation.
0
2695
by: peradino | last post by:
Hi I have a problem when I want to know how far my cursor is from the top of pictureBox. I can get mouse coordinate but it is screen coordinate. I can get the top position of my pictureBox but it is the distance from its container, not the screen coordinate. So my question is... 1.How can I get the top position of pictureBox in screen...
5
10299
by: GoGs | last post by:
How this vb6 code convert in c# dotnet2 ----- Image1.Visible = False Image1.Picture = LoadPicture("c:\image008.jpg") Dim x, y As Single x = Image1.Width y = Image1.Height Do While x Picture1.Width Or y Picture1.Height x = x / 1.01
2
8582
by: =?Utf-8?B?Sm9uIFBhcnJ5?= | last post by:
Hi, I've got a Picturebox, into which I am putting a frame bitmap from a video camera. The camera bitmap is larger than the picturebox, which has SizeMode set to "Zoom" which causes the bitmap to be resized and correctly displayed. My question is whether letting the Picturebox do the bitmap resizing is the most efficient mechanism, or...
0
7601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7913
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7659
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6274
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2099
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.