Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Vertical Text Orientation For Printing

Vertical Text Orientation For Printing

Vertical Text Orientation For Printing

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 ?

RE: Vertical Text Orientation For Printing


The following code snippets refer to the following modules.
Name: CLogFont
Type: Standard Class Module

Name: Form1
Type: Standard Form
Objects: Picturebox (Name Picture1)

1. Copy the snippets between the ~~~~ delimiters to the appropriate module.
2. Add a Picture Box to Form1. Leave it named Picture1
3. Run the project
4.Click the Picture box and the text will be displayed at 45 degrees. I'll leave the rest for you to discover.

All this code was courtesy of
Karl E. Peterson
Ask The VB Pro Section
Visual Basic Programmers Journal
Jan 1999

Start Class Module: CLogFont
Option Explicit

' Logical Font
Private Const LF_FACESIZE = 32
Private Const LF_FULLFACESIZE = 64

Private Const CLIP_STROKE_PRECIS = 2
Private Const CLIP_MASK = &HF
Private Const CLIP_LH_ANGLES = 16
Private Const CLIP_TT_ALWAYS = 32
Private Const CLIP_EMBEDDED = 128

Private Const DEFAULT_QUALITY = 0
Private Const DRAFT_QUALITY = 1
Private Const PROOF_QUALITY = 2

Private Const DEFAULT_PITCH = 0
Private Const FIXED_PITCH = 1
Private Const VARIABLE_PITCH = 2

Private Const ANSI_CHARSET = 0
Private Const DEFAULT_CHARSET = 1
Private Const SYMBOL_CHARSET = 2
Private Const SHIFTJIS_CHARSET = 128
Private Const HANGEUL_CHARSET = 129
Private Const CHINESEBIG5_CHARSET = 136
Private Const OEM_CHARSET = 255

' Font Families
Private Const FF_DONTCARE = 0 ' Don't care or don't know.
Private Const FF_ROMAN = 16 ' Variable stroke width, serifed.

' Times Roman, Century Schoolbook, etc.
Private Const FF_SWISS = 32 ' Variable stroke width, sans-serifed.

' Helvetica, Swiss, etc.
Private Const FF_MODERN = 48 ' Constant stroke width, serifed or sans-serifed.

' Pica, Elite, Courier, etc.
Private Const FF_SCRIPT = 64 ' Cursive, etc.
Private Const FF_DECORATIVE = 80 ' Old English, etc.

' Font Weights
Private Const FW_DONTCARE = 0
Private Const FW_THIN = 100
Private Const FW_EXTRALIGHT = 200
Private Const FW_LIGHT = 300
Private Const FW_NORMAL = 400
Private Const FW_MEDIUM = 500
Private Const FW_SEMIBOLD = 600
Private Const FW_BOLD = 700
Private Const FW_EXTRABOLD = 800
Private Const FW_HEAVY = 900

Private Const FW_BLACK = FW_HEAVY

Private Const OUT_DEFAULT_PRECIS = 0
Private Const OUT_STRING_PRECIS = 1
Private Const OUT_STROKE_PRECIS = 3
Private Const OUT_TT_PRECIS = 4
Private Const OUT_DEVICE_PRECIS = 5
Private Const OUT_RASTER_PRECIS = 6
Private Const OUT_TT_ONLY_PRECIS = 7
Private Const OUT_OUTLINE_PRECIS = 8

Private Type LogFont
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName As String * LF_FACESIZE
End Type

Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LogFont) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long

Private Const LOGPIXELSY = 90 ' Logical pixels/inch in Y

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long

Private m_Font As StdFont
Private m_hFont As Long
Private m_Rotation As Single

Private Sub Class_Terminate()
' Clean-up created objects!!!
If m_hFont Then
Call DeleteObject(m_hFont)
Set m_Font = Nothing
End If
End Sub

Public Property Set LogFont(ByVal NewFont As Font)
If m_hFont Then
Call DeleteObject(m_hFont)
m_hFont = 0
End If

If NewFont Is Nothing Then
Set m_Font = Nothing
' Stash a copy of the passed object,
' to avoid a new reference to it.
Set m_Font = New StdFont
With m_Font
.Bold = NewFont.Bold
.Charset = NewFont.Charset
.Italic = NewFont.Italic
.Name = NewFont.Name
.Size = NewFont.Size
.Strikethrough = NewFont.Strikethrough
.Underline = NewFont.Underline
.Weight = NewFont.Weight
End With
m_hFont = CreateLogFont
End If
End Property

Public Property Get LogFont() As Font
Set LogFont = m_Font
End Property

Public Property Let Rotation(ByVal NewVal As Single)
If NewVal <> m_Rotation Then
m_Rotation = NewVal
If m_hFont Then
Call DeleteObject(m_hFont)
m_hFont = 0
End If
If Not (m_Font Is Nothing) Then
m_hFont = CreateLogFont
End If
End If
End Property

Public Property Get Rotation() As Single
Rotation = m_Rotation
End Property

Public Property Get Handle() As Long
Handle = m_hFont
End Property

Private Function CreateLogFont() As Long
Dim lf As LogFont
Dim hWnd As Long
Dim hDC As Long

hWnd = GetDesktopWindow
hDC = GetDC(hWnd)

With lf
' All but two properties are very straight-forward,
' even with rotation, and map directly.
.lfHeight = -(m_Font.Size * GetDeviceCaps(hDC, LOGPIXELSY)) / 72
.lfWidth = 0
.lfEscapement = m_Rotation * 10
.lfOrientation = .lfEscapement
.lfWeight = m_Font.Weight
.lfItalic = m_Font.Italic
.lfUnderline = m_Font.Underline
.lfStrikeOut = m_Font.Strikethrough
.lfClipPrecision = CLIP_DEFAULT_PRECIS
.lfQuality = PROOF_QUALITY
.lfFaceName = m_Font.Name & vbNullChar
' OEM fonts can't rotate, and we must force
' substitution with something ANSI.
.lfCharSet = m_Font.Charset
If .lfCharSet = OEM_CHARSET Then
If (m_Rotation Mod 360) <> 0 Then
End If
End If
' Only TrueType fonts can rotate, so we must
' specify TT-only if angle is not zero.
If (m_Rotation Mod 360) <> 0 Then
.lfOutPrecision = OUT_TT_ONLY_PRECIS
.lfOutPrecision = OUT_DEFAULT_PRECIS
End If
End With

CreateLogFont = CreateFontIndirect(lf)
Call ReleaseDC(hWnd, hDC)
End Function
End Class Module

Start Form Module - Form1
Option Explicit
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private fnt As CLogFont

Private Sub Form_Load()
Set fnt = New CLogFont
Set fnt.LogFont = Picture1.Font
fnt.Rotation = 45

End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim hFont As Long
With Picture1
hFont = SelectObject(.hDC, fnt.Handle)
.CurrentX = X
.CurrentY = Y
Picture1.Print "Degrees: " & fnt.Rotation

Call SelectObject(.hDC, hFont)

End With
End Sub

End Form Module

RE: Vertical Text Orientation For Printing


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.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close