As you may know already, after making the selections on the dialog box, the user can click OK. In this case, when you call the ShowDialog() method, you can find out whether this method returns DialogResult::OK. If it does, you can get all the returned values of the dialog box to know what changes the user made. Besides OK and Cancel, you can equip a font dialog box with a button labeled Apply. To support this, the FontDialog class is equipped with a Boolean property named ShowApply: public: property bool ShowApply { bool get (); void set (bool value); } By default, this property is set to false, which means the button would be hidden. If you want to show the button, set this property to true. Here is an example: void btnShowClick(Object ^ sender, EventArgs ^ e) { FontDialog ^dlgFont = gcnew FontDialog; dlgFont->ShowApply = true; dlgFont->ShowDialog(); } This would produce:
As opposed to the OK button, when the user clicks Apply, the dialog box does not close and therefore (its ShowDialog() method) does not return a DialogResult result. Instead, the dialog box fires an Apply event. This event is of type EventArgs, which means it does not give you information about what the user did (or did not do). Fortunately, to get information about the state or the values of the dialog, you can simply inquire about its various properties and you would get all the information you need without any effort.
We have already mentioned that the Font dialog box can display or not display the Effects group box. This characteristic is controlled by the ShowEffects Boolean property. When this property is set to true, the dialog box would display an Effects group box that contains a Strikeout and an Underline check boxes. If the ShowEffects property is set to false, the whole section would be hidden. Here is an example: void btnShowClick(Object ^ sender, EventArgs ^ e)
{
FontDialog ^ dlgFont = gcnew FontDialog;
dlgFont->ShowEffects = false;
dlgFont->ShowDialog();
}
Besides the font definition, you may want the user to apply a color to the font. To support this, the FontDialog class is equipped with the ShowColor Boolean property: public: property bool ShowColor { bool get (); void set (bool value); } By default, this property is set to false. Because the Color combo box is contained in the Effects group box, before being able to display it, you must set the ShowEffects property to true. Then, to show the Color combo box, you can set its property to true. Here is an example: void btnShowClick(Object ^ sender, EventArgs ^ e)
{
FontDialog ^ dlgFont = gcnew FontDialog;
dlgFont->ShowEffects = true;
dlgFont->ShowColor = true;
dlgFont->ShowDialog();
}
If the Font dialog box is configured to show the Color combo box, by default, when the dialog box displays, the Color combo box selects the black color. If you want, you can make it display a different color. To do this, at design time, access the Properties window for the FontDialog object, click the arrow of the Color field and select a color. To programmatically specify a color, assign the desired color to the Color property: void btnShowClick(Object ^ sender, EventArgs ^ e) { FontDialog ^ dlgFont = gcnew FontDialog; dlgFont->ShowEffects = true; dlgFont->ShowColor = true; dlgFont->Color = Color::Red; dlgFont->ShowDialog(); } This would produce:
After using the dialog box, if the user had selected a color and clicked OK (or Apply), to find out the color the user had selected, get the value of the Color property. |
|
|||||||
|