|
|
Title | Set a scaling transformation on a Graphics object and map mouse positions back into world coordinates in VB .NET |
Description | This example shows how to set a scaling transformation on a Graphics object and map mouse positions back into world coordinates in VB .NET. It builds the transformation and uses the inverse transformation to map the mouse positions. |
Keywords | VB.NET, scale, scalemode, scalex, scaley, graph, transform, transformation, invert, inverse |
Categories | Graphics |
|
|
See the example Set a scaling transformation on a Graphics object in VB .NET for information about building the scaling transformation.
After it uses the SetScale subroutine to build the transformation, the program saves a copy of the transformation and inverts it. The original transformation maps from world (data) coordinates to screen coordinates. The inverted transformation does the reverse.
|
|
...
' Set viewport (-10, -10) to (110, 110).
Dim gr As Graphics = e.Graphics
SetScale(gr, Me.ClientSize.Width, Me.ClientSize.Height, _
-10, 110, 110, -10)
' Save the inverted transformation matrix.
m_InverseTransformation = gr.Transform
m_InverseTransformation.Invert()
...
|
|
When the mouse moves over the form, the program uses the inverted transformation matrix's TransformPoints method to map the point back into world coordinates.
|
|
' Display the mouse's coordinates.
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseMove
' Apply the inverted transformation to the point.
Dim ptfs() As PointF = {New PointF(e.X, e.Y)}
m_InverseTransformation.TransformPoints(ptfs)
' Display the result.
Me.Text = "Scales (" & _
ptfs(0).X.ToString("0.0") & ", " & _
ptfs(0).Y.ToString("0.0") & ")"
End Sub
|
|
|
|
|
|