Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleDraw untransformed text at a transformed location in VB .NET
DescriptionThis example shows how to draw untransformed text at a transformed location in VB .NET. The program uses the Graphics object's transformation methods to define the transformation. It then uses the transformation's TransformPoints method to find the transformed location.
Keywordstransform, transformation, text, font, VB.NET
CategoriesGraphics, VB.NET
 
The program's Paint event handler uses the Graphics object's transformation methods to define the transformation. It then draws a transformed rectangle and ellipses.

The Graphics object's Transform property returns the transformation. The code uses this object's TransformPoints method to see where the point (0, 0) is mapped by the transformation. It resets the transformation to remove it and calls DrawString to draw the untransformed text at the transformed location.

 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    ' Draw a transformed rectangle and some ellipses.
    e.Graphics.ScaleTransform(1.5, 1.5, MatrixOrder.Append)
    e.Graphics.TranslateTransform(80, 20)
    e.Graphics.RotateTransform(20, MatrixOrder.Append)

    e.Graphics.DrawRectangle(Pens.Blue, 0, 0, 100, 100)
    e.Graphics.DrawEllipse(Pens.Red, -3, -3, 6, 6)
    e.Graphics.DrawEllipse(Pens.Yellow, 97, 97, 6, 6)

    ' Draw untransformed text starting at the
    ' transformed location (0, 0).

    ' Transform the point (0, 0) to see where it goes.
    Dim pts() As Point = {New Point(0, 0)}
    e.Graphics.Transform.TransformPoints(pts)

    ' Reset the transformation.
    e.Graphics.ResetTransform()

    ' Draw the text at the transformed point.
    Dim the_font As New Font("Times New Roman", 20, _
        FontStyle.Regular, GraphicsUnit.Pixel)
    e.Graphics.DrawString("WYSIWYG", the_font, _
        Brushes.Brown, _
        pts(0).X, pts(0).Y)
    the_font.Dispose()
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated