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
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.
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. |