-
I need to send a text string to the printer but I need the text printed vertically down the side of a bitmap. This is driving my crazy ! I have tried changing the orientation property when I get to the point that I want to print the text but I am told I can't do this during a print job. I can't find any rotate method or anything else which looks as though it will help.
Surely there is a way to do this in vb ??
-
Hi, there.
This code will print text vertically on a form. Don't know if it will be useful for you:
Code:
Option Explicit
Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
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
Private Sub Form_Resize()
Const FW_NORMAL = 400 ' Normal font weight.
' Start from scratch.
Cls
DrawRotatedText "Hello", 700, 700, _
"Times New Roman", 20, _
FW_NORMAL, 880, _
False, False, False
End Sub
Larisa
-
Thanks a lot.. This should do exactly what I want I think.