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
Keywordsrotate, text, CreateFont
CategoriesGraphics
 
Use the CreateFont API function to create rotated text.

My book Visual Basic Graphics Programming describes rotated fonts further. It shows how to make text follow a path and how to precisely find font properties such as the empty area around the text.

My book Custom Controls Library implements custom controls that display rotated text and text that follows a path.

 
Private Sub DrawRotatedText(ByVal txt As String, _
    ByVal X As Single, ByVal Y As Single, _
    ByVal font_name As String, ByVal size As Long, _
    ByVal weight As Long, ByVal escapement As Long, _
    ByVal use_italic As Boolean, ByVal use_underline As _
        Boolean, _
    ByVal use_strikethrough As Boolean)

Const CLIP_LH_ANGLES = 16   ' Needed for tilted fonts.
Const PI = 3.14159625
Const PI_180 = PI / 180#

Dim newfont As Long
Dim oldfont As Long

    newfont = CreateFont(size, 0, _
        escapement, escapement, weight, _
        use_italic, use_underline, _
        use_strikethrough, 0, 0, _
        CLIP_LH_ANGLES, 0, 0, font_name)
    
    ' Select the new font.
    oldfont = SelectObject(hdc, newfont)
    
    ' Display the text.
    CurrentX = X
    CurrentY = Y
    Print txt

    ' Restore the original font.
    newfont = SelectObject(hdc, oldfont)
    
    ' Free font resources (important!)
    DeleteObject newfont
End Sub
 
Note that rotated text looks best when the font is relatively large.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated