Figure 17.6 shows the Font dialog box that the common dialog box control produces.
The Font dialog box provides a font selection.
The fonts vary depending on the computer on which your application is running. The Font dialog box ensures that the font is available to your application, because the fonts come from the current machine and not from the computer that produced the program. Before you print or display certain text, you may want to give each user a chance to format the text (perhaps with the Format menu's standard Font command), so display the Font dialog box and then assign the selected values to the user's text.
You must set the proper Font dialog box Flags value from Table 17.2. Otherwise, the Font dialog box won't appear.
Table 17.2 Font Dialog Box Flags Values
Named Literal | Flags Value | Description |
cdlCFANSIOnly | &H400 | Ensures that the dialog box allows only fonts from the Windows character set and not a symbol-based font |
cdlCFApply | &H200 | Enables the dialog box's Apply button |
cdlCFBoth | &H3 | Lists the available printer and screen fonts in the dialog box; the hDC property identifies the device context associated with the printer |
cdlCFEffects | &H100 | Lets the dialog box enable strikethrough, underline, and color effects |
cdlCFFixedPitchOnly | &H4000 | Ensures that the dialog box selects only fixed-pitch fonts |
cdlCFForceFontExist | &H10000 | Displays an error message box if users try to select a font or style that doesn't exist |
cdlCFHelpButton | &H4 | Displays the dialog box's Help button |
cdlCFLimitSize | &H2000 | Ensures that the dialog box selects only font sizes within the range specified by the Min and Max properties |
cdlCFNoFaceSel | &H80000 | No font name is selected as the default |
cdlCFNoSimulations | &H1000 | Disallows graphic device interface (GDI) font simulations |
cdlCFNoSizeSel | &H200000 | No font size is selected as the default |
cdlCFNoStyleSel | &H100000 | No font style is selected as the default |
cdlCFNoVectorFonts | &H800 | Disallows vector-font selections |
cdlCFPrinterFonts | &H2 | Lists only the fonts supported by the printer, specified by the hDC property |
cdlCFScalableOnly | &H20000 | Allows only the selection of scalable fonts |
cdlCFScreenFonts | &H1 | Lists only the screen fonts supported by the system |
cdlCFTTOnly | &H40000 | Allows only the selection of TrueType fonts |
cdlCFWYSIWYG | &H8000 | Specifies that the dialog box allows only the selection of fonts available on the printer and on-screen (if you set this flag, you should also set cdlCFBoth and cdlCFScalableOnly) |
You must set at least one of the following values before the Font dialog box appears correctly: cdlCFScreenFonts, cdlCFPrinterFonts, or cdlCFBoth. Otherwise, Visual Basic issues an error message.
![]()
You may need to set more than one Flags value, such as cdlCFNoStyleSel and cdlCFScreenFonts. Use the logical And or Or operator to combine these Flags values, as in the following assignment:
cdbFontDB.Flags = cdlCFNoStyleSel And cdlCFScreenFonts
After you set the Flags property, apply the ShowFont method to the dialog box to display the Fonts dialog box. You can't set multiple Flags at design time, only at runtime.