Setting the Font


These two statements are used to control the font characteristics for the Gauge control:

 Dim MyStyle As FontStyle = FontStyle.Regular  Dim MyFont As Font = New Font("Microsoft Sans Serif", 8, MyStyle) 

The available font styles are presented in Table 22.2.

Table 22.2. The Available Font Styles

Font Style

Description

Bold

Uses boldface on the font

Italic

Italicizes the font

Regular

Uses normal text

Strikeout

Displays each character with a line drawn through the middle

Underline

Underlines each character

Actually, each font characteristic is an Enum data type and can be combined together with a logical Or to produce combined font effects. For example, if you change the definition of MyStyle to this:

 Dim MyStyle As FontStyle = FontStyle.Regular Or FontStyle.Underline 

the result is underlined regular text.

The MyStyle font style is used to set the font itself. In this statement:

 Dim MyFont As Font = New Font("Microsoft Sans Serif", 8, MyStyle) 

the quoted string is the font family name for the font you want to use, followed by the point size and then the font style, as held in MyStyle .

You might think that you could select any font from the standard font dialog box, copy the string name into the first argument for the Font() method, and be done with it. Well, not exactly. Figure 22.8 shows what happened when I tried to set the font to Monotype Corsiva. The runtime error message makes it clear that all font types may not support all style characteristics.

Figure 22.8. An example of an error message for an invalid font style.

graphics/22fig08.jpg

If you change the font style for MyStyle to Font.Italics and use the Monotype Corsiva font in the Font() method call, the code works fine.

After the font has been set, several working variables are defined, and a call to SetGaugeParameters() is made to initialize some of the values used to draw the gauge, as explained earlier in the chapter.



Visual Basic .NET. Primer Plus
Visual Basic .NET Primer Plus
ISBN: 0672324857
EAN: 2147483647
Year: 2003
Pages: 238
Authors: Jack Purdum

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net