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
 
 
 
 
 
 
TitlePosition text rotated 90 degrees
Keywordsposition text, rotate,
CategoriesGraphics, Utilities
 

Use the CreateFont API function to make the rotated font.

Use the TextWidth method to get the rotated text's width. Use the font size to see how tall the text is. Use the text's dimensions to calculate where the text must start to align it centered or on different corners.

My book Visual Basic Graphics Programming has more to say about rotated text. It shows how to find the exact bounding box of text with and without the space above the text for any angle of rotation.

 
Private Sub Picture1_Resize()
Const FW_NORMAL = 400   ' Normal font weight.
Const FW_BOLD = 700     ' Bold font weight.
Const FONT_SIZE = 20

Dim txt As String
Dim wid As Single
Dim hgt As Single
Dim X As Single
Dim Y As Single

    Picture1.AutoRedraw = True
    Picture1.ScaleMode = vbPixels
    Picture1.Cls

    ' Upper left.
    txt = "Upper Left"
    SelectFont Picture1, "Times New Roman", _
        FONT_SIZE, FW_BOLD, 900, False, False, False
    wid = Picture1.TextWidth(txt)
    hgt = FONT_SIZE
    X = 0
    Y = wid
    Picture1.CurrentX = X
    Picture1.CurrentY = Y
    Picture1.Print txt
    Picture1.Line (X, Y)-Step(hgt, -wid), , B
    DeselectFont Picture1

    ' Upper right.
    txt = "Upper Right"
    SelectFont Picture1, "Times New Roman", _
        FONT_SIZE, FW_BOLD, 900, False, False, False
    wid = Picture1.TextWidth(txt)
    hgt = FONT_SIZE
    X = Picture1.ScaleWidth - hgt
    Y = wid
    Picture1.CurrentX = X
    Picture1.CurrentY = Y
    Picture1.Print txt
    Picture1.Line (X, Y)-Step(hgt, -wid), , B
    DeselectFont Picture1

    ' Lower left.
    txt = "Lower Left"
    SelectFont Picture1, "Times New Roman", _
        FONT_SIZE, FW_BOLD, 900, False, False, False
    wid = Picture1.TextWidth(txt)
    hgt = FONT_SIZE
    X = 0
    Y = Picture1.ScaleHeight
    Picture1.CurrentX = X
    Picture1.CurrentY = Y
    Picture1.Print txt
    Picture1.Line (X, Y)-Step(hgt, -wid), , B
    DeselectFont Picture1

    ' Lower right.
    txt = "Lower Right"
    SelectFont Picture1, "Times New Roman", _
        FONT_SIZE, FW_BOLD, 900, False, False, False
    wid = Picture1.TextWidth(txt)
    hgt = FONT_SIZE
    X = Picture1.ScaleWidth - hgt
    Y = Picture1.ScaleHeight
    Picture1.CurrentX = X
    Picture1.CurrentY = Y
    Picture1.Print txt
    Picture1.Line (X, Y)-Step(hgt, -wid), , B
    DeselectFont Picture1

    ' Center.
    txt = "Center"
    SelectFont Picture1, "Times New Roman", _
        FONT_SIZE, FW_BOLD, 900, False, False, False
    wid = Picture1.TextWidth(txt)
    hgt = FONT_SIZE
    X = (Picture1.ScaleWidth - hgt) / 2
    Y = (Picture1.ScaleHeight + wid) / 2
    Picture1.CurrentX = X
    Picture1.CurrentY = Y
    Picture1.Print txt
    Picture1.Line (X, Y)-Step(hgt, -wid), , B
    DeselectFont Picture1

    Picture1.Line (0, 0)-(Picture1.ScaleWidth, _
        Picture1.ScaleHeight)
    Picture1.Line (0, _
        Picture1.ScaleHeight)-(Picture1.ScaleWidth, 0)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated