Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vertical Text Orientation For Printing 1

Status
Not open for further replies.

Trojan

Programmer
Nov 26, 1999
5
GB
I am using VB 5, and want to print out a table, but would like the text of the header row to be printed vertically up the page. I don't want to use MSChart if I can possibly avoid it. Is there any way to do this ?<br>

 
Trojan:<br>
<br>
The following code snippets refer to the following modules.<br>
Name: CLogFont<br>
Type: Standard Class Module<br>
<br>
Name: Form1<br>
Type: Standard Form<br>
Objects: Picturebox (Name Picture1)<br>
<br>
1. Copy the snippets between the ~~~~ delimiters to the appropriate module.<br>
2. Add a Picture Box to Form1. Leave it named Picture1<br>
3. Run the project<br>
4.Click the Picture box and the text will be displayed at 45 degrees. I'll leave the rest for you to discover.<br>
<br>
All this code was courtesy of <br>
Karl E. Peterson<br>
Ask The VB Pro Section<br>
Visual Basic Programmers Journal<br>
Jan 1999<br>
<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
Start Class Module: CLogFont<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
Option Explicit<br>
<br>
' Logical Font<br>
Private Const LF_FACESIZE = 32<br>
Private Const LF_FULLFACESIZE = 64<br>
<br>
Private Const CLIP_DEFAULT_PRECIS = 0<br>
Private Const CLIP_CHARACTER_PRECIS = 1<br>
Private Const CLIP_STROKE_PRECIS = 2<br>
Private Const CLIP_MASK = &HF<br>
Private Const CLIP_LH_ANGLES = 16<br>
Private Const CLIP_TT_ALWAYS = 32<br>
Private Const CLIP_EMBEDDED = 128<br>
<br>
Private Const DEFAULT_QUALITY = 0<br>
Private Const DRAFT_QUALITY = 1<br>
Private Const PROOF_QUALITY = 2<br>
<br>
Private Const DEFAULT_PITCH = 0<br>
Private Const FIXED_PITCH = 1<br>
Private Const VARIABLE_PITCH = 2<br>
<br>
Private Const ANSI_CHARSET = 0<br>
Private Const DEFAULT_CHARSET = 1<br>
Private Const SYMBOL_CHARSET = 2<br>
Private Const SHIFTJIS_CHARSET = 128<br>
Private Const HANGEUL_CHARSET = 129<br>
Private Const CHINESEBIG5_CHARSET = 136<br>
Private Const OEM_CHARSET = 255<br>
<br>
' Font Families<br>
'<br>
Private Const FF_DONTCARE = 0 ' Don't care or don't know.<br>
Private Const FF_ROMAN = 16 ' Variable stroke width, serifed.<br>
<br>
' Times Roman, Century Schoolbook, etc.<br>
Private Const FF_SWISS = 32 ' Variable stroke width, sans-serifed.<br>
<br>
' Helvetica, Swiss, etc.<br>
Private Const FF_MODERN = 48 ' Constant stroke width, serifed or sans-serifed.<br>
<br>
' Pica, Elite, Courier, etc.<br>
Private Const FF_SCRIPT = 64 ' Cursive, etc.<br>
Private Const FF_DECORATIVE = 80 ' Old English, etc.<br>
<br>
' Font Weights<br>
Private Const FW_DONTCARE = 0<br>
Private Const FW_THIN = 100<br>
Private Const FW_EXTRALIGHT = 200<br>
Private Const FW_LIGHT = 300<br>
Private Const FW_NORMAL = 400<br>
Private Const FW_MEDIUM = 500<br>
Private Const FW_SEMIBOLD = 600<br>
Private Const FW_BOLD = 700<br>
Private Const FW_EXTRABOLD = 800<br>
Private Const FW_HEAVY = 900<br>
<br>
Private Const FW_ULTRALIGHT = FW_EXTRALIGHT<br>
Private Const FW_REGULAR = FW_NORMAL<br>
Private Const FW_DEMIBOLD = FW_SEMIBOLD<br>
Private Const FW_ULTRABOLD = FW_EXTRABOLD<br>
Private Const FW_BLACK = FW_HEAVY<br>
<br>
Private Const OUT_DEFAULT_PRECIS = 0<br>
Private Const OUT_STRING_PRECIS = 1<br>
Private Const OUT_CHARACTER_PRECIS = 2<br>
Private Const OUT_STROKE_PRECIS = 3<br>
Private Const OUT_TT_PRECIS = 4<br>
Private Const OUT_DEVICE_PRECIS = 5<br>
Private Const OUT_RASTER_PRECIS = 6<br>
Private Const OUT_TT_ONLY_PRECIS = 7<br>
Private Const OUT_OUTLINE_PRECIS = 8<br>
<br>
Private Type LogFont<br>
lfHeight As Long<br>
lfWidth As Long<br>
lfEscapement As Long<br>
lfOrientation As Long<br>
lfWeight As Long<br>
lfItalic As Byte<br>
lfUnderline As Byte<br>
lfStrikeOut As Byte<br>
lfCharSet As Byte<br>
lfOutPrecision As Byte<br>
lfClipPrecision As Byte<br>
lfQuality As Byte<br>
lfPitchAndFamily As Byte<br>
lfFaceName As String * LF_FACESIZE<br>
End Type<br>
<br>
Private Declare Function CreateFontIndirect Lib &quot;gdi32&quot; Alias &quot;CreateFontIndirectA&quot; (lpLogFont As LogFont) As Long<br>
Private Declare Function DeleteObject Lib &quot;gdi32&quot; (ByVal hObject As Long) As Long<br>
Private Declare Function GetDeviceCaps Lib &quot;gdi32&quot; (ByVal hDC As Long, ByVal nIndex As Long) As Long<br>
<br>
Private Const LOGPIXELSY = 90 ' Logical pixels/inch in Y<br>
<br>
Private Declare Function GetDesktopWindow Lib &quot;user32&quot; () As Long<br>
Private Declare Function GetDC Lib &quot;user32&quot; (ByVal hWnd As Long) As Long<br>
Private Declare Function ReleaseDC Lib &quot;user32&quot; (ByVal hWnd As Long, ByVal hDC As Long) As Long<br>
<br>
Private m_Font As StdFont<br>
Private m_hFont As Long<br>
Private m_Rotation As Single<br>
<br>
Private Sub Class_Terminate()<br>
'<br>
' Clean-up created objects!!!<br>
'<br>
If m_hFont Then<br>
Call DeleteObject(m_hFont)<br>
Set m_Font = Nothing<br>
End If<br>
End Sub<br>
<br>
Public Property Set LogFont(ByVal NewFont As Font)<br>
If m_hFont Then<br>
Call DeleteObject(m_hFont)<br>
m_hFont = 0<br>
End If<br>
<br>
If NewFont Is Nothing Then<br>
Set m_Font = Nothing<br>
Else<br>
'<br>
' Stash a copy of the passed object,<br>
' to avoid a new reference to it.<br>
'<br>
Set m_Font = New StdFont<br>
With m_Font<br>
.Bold = NewFont.Bold<br>
.Charset = NewFont.Charset<br>
.Italic = NewFont.Italic<br>
.Name = NewFont.Name<br>
.Size = NewFont.Size<br>
.Strikethrough = NewFont.Strikethrough<br>
.Underline = NewFont.Underline<br>
.Weight = NewFont.Weight<br>
End With<br>
m_hFont = CreateLogFont<br>
End If<br>
End Property<br>
<br>
Public Property Get LogFont() As Font<br>
Set LogFont = m_Font<br>
End Property<br>
<br>
Public Property Let Rotation(ByVal NewVal As Single)<br>
If NewVal &lt;&gt; m_Rotation Then<br>
m_Rotation = NewVal<br>
If m_hFont Then<br>
Call DeleteObject(m_hFont)<br>
m_hFont = 0<br>
End If<br>
If Not (m_Font Is Nothing) Then<br>
m_hFont = CreateLogFont<br>
End If<br>
End If<br>
End Property<br>
<br>
Public Property Get Rotation() As Single<br>
Rotation = m_Rotation<br>
End Property<br>
<br>
Public Property Get Handle() As Long<br>
Handle = m_hFont<br>
End Property<br>
<br>
Private Function CreateLogFont() As Long<br>
Dim lf As LogFont<br>
Dim hWnd As Long<br>
Dim hDC As Long<br>
<br>
hWnd = GetDesktopWindow<br>
hDC = GetDC(hWnd)<br>
<br>
With lf<br>
'<br>
' All but two properties are very straight-forward,<br>
' even with rotation, and map directly.<br>
'<br>
.lfHeight = -(m_Font.Size * GetDeviceCaps(hDC, LOGPIXELSY)) / 72<br>
.lfWidth = 0<br>
.lfEscapement = m_Rotation * 10<br>
.lfOrientation = .lfEscapement<br>
.lfWeight = m_Font.Weight<br>
.lfItalic = m_Font.Italic<br>
.lfUnderline = m_Font.Underline<br>
.lfStrikeOut = m_Font.Strikethrough<br>
.lfClipPrecision = CLIP_DEFAULT_PRECIS<br>
.lfQuality = PROOF_QUALITY<br>
.lfPitchAndFamily = DEFAULT_PITCH Or FF_DONTCARE<br>
.lfFaceName = m_Font.Name & vbNullChar<br>
'<br>
' OEM fonts can't rotate, and we must force<br>
' substitution with something ANSI.<br>
'<br>
.lfCharSet = m_Font.Charset<br>
If .lfCharSet = OEM_CHARSET Then<br>
If (m_Rotation Mod 360) &lt;&gt; 0 Then<br>
.lfCharSet = ANSI_CHARSET<br>
End If<br>
End If<br>
'<br>
' Only TrueType fonts can rotate, so we must<br>
' specify TT-only if angle is not zero.<br>
'<br>
If (m_Rotation Mod 360) &lt;&gt; 0 Then<br>
.lfOutPrecision = OUT_TT_ONLY_PRECIS<br>
Else<br>
.lfOutPrecision = OUT_DEFAULT_PRECIS<br>
End If<br>
End With<br>
<br>
CreateLogFont = CreateFontIndirect(lf)<br>
Call ReleaseDC(hWnd, hDC)<br>
End Function<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
End Class Module<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
Start Form Module - Form1<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
Option Explicit<br>
Private Declare Function SelectObject Lib &quot;gdi32&quot; (ByVal hDC As Long, ByVal hObject As Long) As Long<br>
Private fnt As CLogFont<br>
<br>
Private Sub Form_Load()<br>
Set fnt = New CLogFont<br>
Set fnt.LogFont = Picture1.Font<br>
fnt.Rotation = 45<br>
<br>
End Sub<br>
<br>
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)<br>
Dim hFont As Long<br>
With Picture1<br>
hFont = SelectObject(.hDC, fnt.Handle)<br>
.CurrentX = X<br>
.CurrentY = Y<br>
Picture1.Print &quot;Degrees: &quot; & fnt.Rotation<br>
<br>
Call SelectObject(.hDC, hFont)<br>
<br>
End With<br>
End Sub<br>
<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
End Form Module<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>

 
Nate,<br>
<br>
Thanks for your help. I am fairly new to all this, and I appreciate your assistance very much. It is clear to me from reading through your response that I would have never have discovered the solution by myself.<br>
<br>
Cheers,<br>
<br>
Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top