Page 1
Page 2
Introduction
A few weeks ago, in my daily browsing
of newsgroups and developer lists, I came across an innocuous
question posted by another developer looking for some help.
"How do I display a Label vertically on my Form?"
It's a reasonable question and the ability to display text
in an orientation other than horizontal is nice in a lot
of situations. The challenge was going to be getting eVB,
with all of its inherent limitations, to play along.

Windows Fonts
Fonts are actually quite complex so
for the scope of this article I'll keep everything down
to a "need to know" basis.
The first thing you need to know is
that text is drawn directly into a Device Context or
DC. A DC is most often part of a Window delineated
by a rectangle, though you can create a DC that is not in
any visible window for doing things like blitting and masking.
For us to draw a font on our Form, we need to obtain a handle
to a DC (an hDC), and fortunately eVB Forms expose an hDC
property directly.
Next you need to know that in order
to draw text you have to either select a stock logical font
or create your own logical font and then tell the hDC to
use that font (called selecting the font into the DC). Creating
a font doesn't mean you have to define each character or
draw them out, you can use an available system font and
simply modify its properties to suit your needs.
Logical fonts are mapped from
the device's available physical fonts. This allows Windows
to provide the closest font to your request if a font with
the exact properties requested does not exist. The properties
of a font are Character set, Pitch, Family, FaceName, Height,
Width, Slant, Underline and StrikeOut.
Creating and Selecting a Logical
Font
The first order of business is to create
a logical font, which is represented as a LOGFONT
structure. Of course eVB doesn't support structures, but
we can work around that minor annoyance by simply creating
a binary string to pass instead.
If you look in the eMbedded Visual Tools
Help, you'll see that the LOGFONT structure is made up of
14 members. The important members for our purposes are Height,
Escapement (angle from x-axis), Weight, Underline, Italic
and StrikeOut. To make things a bit easier, I've created
a function, seen in Listing 1, that builds and returns
a LOGFONT structure as a binary string based on these parameters.
Listing 1
Public Function CreateLogicalFont(Height
As Long, _
Width As Long, _
Escapement As Long, _
Weight As Long, _
Italic As Boolean, _
Underline As Boolean, _
Strikeout As Boolean, _
FaceName As String) As String
Dim lf As String
lf = ToBinaryString(Height, CE_LONG)
lf = lf & ToBinaryString(Width, CE_LONG)
lf = lf & ToBinaryString(Escapement, CE_LONG)
lf = lf & ToBinaryString(Escapement, CE_LONG)
lf = lf & ToBinaryString(Weight, CE_LONG)
If Italic Then
lf = lf & ToBinaryString(1, CE_BYTE)
Else
lf = lf & ToBinaryString(0, CE_BYTE)
End If
If Underline Then
lf = lf & ToBinaryString(1, CE_BYTE)
Else
lf = lf & ToBinaryString(0, CE_BYTE)
End If
If Strikeout Then
lf = lf & ToBinaryString(1, CE_BYTE)
Else
lf = lf & ToBinaryString(0, CE_BYTE)
End If
lf = lf & ToBinaryString(OEM_CHARSET, CE_BYTE)
lf = lf & ToBinaryString(OUT_DEFAULT_PRECIS, CE_BYTE)
lf = lf & ToBinaryString(OUT_DEFAULT_PRECIS, CE_BYTE)
lf = lf & ToBinaryString(DEFAULT_QUALITY, CE_BYTE)
lf = lf & ToBinaryString( _
DEFAULT_PITCH Or FF_DONTCARE, CE_BYTE)
lf = lf & FaceName
lf = lf & ToBinaryString(0, CE_BYTE) ' null terminate
CreateLogicalFont = lf
End Function
Next Page