My Photo
Location: Bangalore, India

Tips to Reduce Abdominal Fat!

Friday, November 04, 2005

Rotate a Word :)

I was looking for a way to print text on user control with vertical alignment. I thought i can easily achieve it. But the challenging part of the job was that the text need to be rotated 90 degrees or 270 degrees rather than just printing each character in text one below the other.

Any way i could reach the goal using the Windows API, CreateFontIndirect. Primarily this function creates a logical font that has the characteristics specified in the specified structure. The font can subsequently be selected as the current font for any device context.

A text can be rotated through any angle using this API. A really useful one while you print text on user controls with vertical alignment.

The function declaration is as follows:

Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long

pLogFont Points to a LOGFONT structure that defines the characteristics of the logical font.

If the function succeeds, the return value is a handle to a logical font. If the function fails, the return value is NULL.

Create a type as below.

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(LF_FACESIZE) As Byte
End Type

Then change the Escapement to rotate font (too bad they did not call it rotation so it could be found in a search). Then create a new font the same as current font but rotated. Now select the font n the Form's device context and now the texts printed will be rotated through angle set at lfEscapement.


Post a Comment

<< Home