Try this (this version prints rotated text in a picturebox control):
Usage:
PrintRotated strDisplay, ctlPic, strFontName,lFontsize, lAngle, CX, CY
strDisplay - string you want displayed
ctlPic - reference to a picturebox control text will display in (minor modification will allow this routine to work in any control with an hDC)
strFontName - name of the font
lFontSize - requested font size in points
lAngle - angle to print at (in 10ths of degree; i.e 3600 in a complete circle)
CX - (optional) X position to start printing
CY - (optional) Y position to start printing
Option Explicit
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) 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
Public Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Public Const LOGPIXELSY = 90
Public Const LF_FACESIZE = 32
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
Public Sub PrintRotated(ByVal strDisplay As String, ByVal ctlPic As PictureBox, ByVal strFontname As String, ByVal lFontSize As Long, ByVal lAngle As Long, Optional ByVal CX As Variant, Optional ByVal CY As Variant)
Dim font As LOGFONT
Dim prevFont As Long, hFont As Long, ret As Long
font.lfEscapement = lAngle
font.lfFaceName = strFontname + Chr$(0)
With ctlPic
font.lfHeight = -lFontSize * GetDeviceCaps(.hdc, LOGPIXELSY) / 72 ' This calc ensures closest size match
hFont = CreateFontIndirect(font)
prevFont = SelectObject(.hdc, hFont) ' Select the new font into device context
' If we don't provide CX and CY parameters display
' rotated text in middle of control
If IsMissing(CX) Then
.CurrentX = .ScaleWidth / 2
Else
.CurrentX = CX
End If
If IsMissing(CY) Then
.CurrentY = .ScaleHeight / 2
Else
.CurrentY = CY
End If
ctlPic.Print strDisplay ' There is a bug, which means that we can't just use .Print
' Clean up by restoring original font.
ret = SelectObject(.hdc, prevFont)
ret = DeleteObject(hFont)
End With
End Sub