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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vertical/rotated text

Status
Not open for further replies.

49er

Programmer
Aug 24, 2000
38
0
0
US
I have an image with four labels across the top. Right now the labels are horizontal across the image. However, the length for the text for the labels forces me to position the labels such that the last one on the right extends far beyond the right side of the image. What I want to do is "rotate" the labels so that they take up less room and stay over the image. Is there an easy way to do this? Thanks.
 
I don't know hoe it is in VB, but I made this in VC with MFC, where is quite simple.
You create a LOGFONT structure -> set the lfEscapment member to the degrees desired -> call CreateFontIndirect methos a CFont object with this LOGFONT -> select this in the current DC with SelectObject -> write the text you need. You can create an ActiveX in VC and the use it in VB(but this ActiveX will depend on MFC42.dll and MSVCRT.DLL you will have to ship with your program)

I think this can be made without MFC but it would be a little more complicated.

Hope this gives you some ideas.s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top