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 rotated text in VB .NET
Keywordsrotate, text, CreateFont, font, VB .NET
CategoriesGraphics, VB.NET
 
Create a GraphicsPath object and use its AddString method to make it represent drawing a string at position (150, 150).

Next make a Matrix object. Use its RotateAt method to make it represent rotation around the point (150, 150).

Call the GraphicsPath object's Transform method to apply the Matrix to the path.

Use the form's CreateGraphics method to make a Graphics object. Finally, use that object's methods to clear the form and draw the transformed GraphicsPath.

 
Private Sub btnDrawText_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnDrawText.Click
    Static angle As Long    ' Angle in degrees.

    ' Make a GraphicsPath that draws the text
    ' at (150, 150).
    Dim graphics_path As New _
        GraphicsPath(Drawing.Drawing2D.FillMode.Winding)
    graphics_path.AddString("Hello", _
        New FontFamily("Times New Roman"), _
        FontStyle.Bold, 40, _
        New Point(150, 150), _
        StringFormat.GenericDefault)

    ' Make a rotation matrix representing 
    ' rotation around the point (150, 150).
    Dim rotation_matrix As New Matrix()
    angle += 20
    rotation_matrix.RotateAt(angle, New PointF(150, 150))

    ' Transform the GraphicsPath.
    graphics_path.Transform(rotation_matrix)

    ' Draw the text.
    With Me.CreateGraphics
        .Clear(Me.BackColor)
        .FillPath(Brushes.Black, graphics_path)
    End With
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated