|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Using A Font Dialog BoxThe Testing Department is calling again. Your new word processor, SuperDuperTextPro, is great, but why cant the users select the font they want to use? You ask, should they be able to do that? The Testing Department says, take a look at the Font dialog box. You use the Common Dialog controls ShowFont method to show a Font dialog box. Note that before you use the ShowFont method, you must set the Flags property of the Common Dialog control to one of three constants to indicate if you want to display screen fonts, printer fonts, or both. The possible values are as follows:
If you dont set one of these in the Flags property, a message box is displayed advising the user that There are no fonts installed, which will probably cause them to panic. To see more possible settings for the Flags property, take a look at the next topic in this chapter. When the user dismisses the Font dialog box by clicking on OK, you can determine their font selections using these properties of the Common Dialog control:
Lets see an example. Here, well let the user set the font, font size, and font styles (like underline and bold) in a text box. We start by setting the Common Dialog controls CancelError property to True so clicking the Cancel button causes a trappable error:
Private Sub Command1_Click()
On Error GoTo Cancel
...
Cancel:
End Sub
Next, we set the Flags property and show the Font dialog box:
Private Sub Command1_Click()
On Error GoTo Cancel
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
CommonDialog1.ShowFont
...
Cancel:
End Sub
Finally, we set the text boxs properties to match what the user set in the Font dialog box:
Private Sub Command1_Click()
On Error GoTo Cancel
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
CommonDialog1.ShowFont
Text1.FontName = CommonDialog1.FontName
Text1.FontBold = CommonDialog1.FontBold
Text1.FontItalic = CommonDialog1.FontItalic
Text1.FontUnderline = CommonDialog1.FontUnderline
Text1.FontSize = CommonDialog1.FontSize
Text1.FontName = CommonDialog1.FontName
Cancel:
End Sub
Now when you run this program and click the button, the Font dialog box appears, as in Figure 11.9.
When you select the font options you want and click on OK, those options are installed in the text box, Text1, as shown in Figure 11.10.
Thats itnow were using Font dialog boxes. The listing for this program, fontdialog.frm, is located in the fontdialog folder on this books accompanying CD-ROM. Setting Font Dialog FlagsYou can set a wide variety of options when using Font dialog boxes by using the Common Dialog controls Flags property. Here are the possible values to use with that property:
You can set more than one flag for a dialog box using the Or operator. For example: CommonDialog1.Flags = &H10& Or &H200& Adding the desired constant values produces the same result.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |