How to Print with Rotated TextID: Q119673
|
You can use the CreateFont or CreateFontIndirect Windows API calls to
obtain a rotated font. This allows printing of rotated text to a Visual
Basic form, picture control, or the printer object.
NOTE: This technique may not work under Windows version 3.0 or when you use
a non-TrueType font.
You can specify the rotation for a font when you request a font from
Windows with the CreateFont or CreateFontIndirect Windows API calls; you do
this by setting the escapement of the desired font. The escapement is
expressed in tenths of degrees of rotation, so an escapement of 450 would
be a 45-degree rotation; an 1800 escapement would be 180 degrees of
rotation.
Once you have obtained a handle to the desired font with
CreateFont/CreateFontIndirect, you can then use the SelectObject Windows
API call to select the font for the device context (DC) of the Visual Basic
printer object or for a Visual Basic form or picture control.
The following is a sample program that demonstrates printing rotated text
in a Visual Basic picture control:
Declare Function CreateFontIndirect Lib "GDI" (lpLogFont As Any)
As Integer
Declare Function SelectObject Lib "GDI" (ByVal hDC As Integer,
ByVal hgdiObj As Integer)
As Integer
Declare Function DeleteObject Lib "GDI" (ByVal hgdiObj As Integer)
As Integer
Type LOGFONT_TYPE
lfHeight As Integer
lfWidth As Integer
lfEscapement As Integer
lfOrientation As Integer
lfWeight As Integer
lfItalic As String * 1
lfUnderline As String * 1
lfStrikeOut As String * 1
lfCharSet As String * 1
lfOutPrecision As String * 1
lfClipPrecision As String * 1
lfQuality As String * 1
lfPitchAndFamily As String * 1
lfFaceName As String * 32
End Type
Sub Command1_Click ()
Dim font As LOGFONT_TYPE
Dim prevFont As Integer, hFont As Integer, ret As Integer
Const FONTSIZE = 12 ' Desired point size of font
font.lfEscapement = 1800 ' 180-degree rotation
font.lfFaceName = "Arial" + Chr$(0)
' Windows expects the font size to be in pixels and to
' be negative if you are specifying the character height
' you want.
font.lfHeight = (FONTSIZE * -20) / Screen.TwipsPerPixelY
hFont = CreateFontIndirect(font)
prevFont = SelectObject(Picture1.hDC, hFont)
Picture1.CurrentX = Picture1.Width \ 2
Picture1.CurrentY = Picture1.Height \ 2
Picture1.Print "Rotated Text"
' Clean up by restoring original font.
ret = SelectObject(Picture1.hDC, prevFont)
ret = DeleteObject(hFont)
Picture1.Print "Normal Text"
End Sub
Additional query words: 3.00 rotate
Keywords : kbcode
Version : 3.00
Platform : WINDOWS
Issue type :
Last Reviewed: June 7, 1999