|
|
Title | Draw text using an extra tall font |
Description | This example shows how to draw text using an extra tall font in Visual Basic 6. It uses the CreateFont API function to make the font. |
Keywords | font, CreateFont, tall font, stretched font, text |
Categories | Graphics |
|
|
Subroutine DrawRotatedText draws the text. It uses the CreateFont API function to make the font, calls the SelectObject API function to select the font, displays its text at the indicated position, and then uses SelectObject API again to reselect the original font.
|
|
Private Sub DrawRotatedText(ByVal txt As String, _
ByVal X As Single, ByVal Y As Single, _
ByVal font_name As String, ByVal hgt As Long, ByVal wid _
As Single, _
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(hgt, wid, _
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 - TextWidth(txt) / 2
CurrentY = Y - TextHeight(txt) / 2
Print txt
' Restore the original font.
newfont = SelectObject(hdc, oldfont)
' Free font resources (important!)
DeleteObject newfont
End Sub
|
|
When the form loads, it calls subroutine DrawRotatedText repeatedly to draw seveal pieces of relatively tall, narrow text.
|
|
Private Sub Form_Load()
Const FW_NORMAL = 400 ' Normal font weight.
Const FW_BOLD = 700 ' Bold
Const FW_HEAVY = 1000 ' Extra bold
Const SKIP = 0.8
Dim X As Single
Dim Y As Single
Dim hgt As Single
Dim wid As Single
AutoRedraw = True
ScaleMode = vbPixels
BackColor = RGB(89, 166, 255)
ForeColor = vbWhite
BackColor = vbWhite
ForeColor = vbBlack
hgt = 75 * 1.5
wid = 20
X = 200
Y = 10
DrawRotatedText "Visual", X, Y, _
"Tahoma", hgt, wid, _
FW_HEAVY, 3600, _
False, False, False
Y = Y + hgt * SKIP
DrawRotatedText "Basic", X, Y, _
"Tahoma", hgt, wid, _
FW_HEAVY, 3600, _
False, False, False
Y = Y + hgt * SKIP
DrawRotatedText "Graphics", X, Y, _
"Tahoma", hgt, wid, _
FW_HEAVY, 3600, _
False, False, False
Y = Y + hgt * SKIP
DrawRotatedText "Programming", X, Y, _
"Tahoma", hgt, wid, _
FW_HEAVY, 3600, _
False, False, False
End Sub
|
|
|
|
|
|