FontDialog::FontMustExist Property

Gets or sets a value indicating whether the dialog box specifies an error condition if the user attempts to select a font or style that does not exist.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
property bool FontMustExist {
	bool get ();
	void set (bool value);
}

Property Value

Type: System::Boolean
true if the dialog box specifies an error condition when the user tries to select a font or style that does not exist; otherwise, false. The default is false.

The following code example demonstrates using the MinSize, MaxSize, ShowEffects and FontMustExist members and handling the Apply event. To run this example paste the following code in a form containing a FontDialog named FontDialog1 and a Button named Button1.

void Button1_Click( System::Object^ sender, System::EventArgs^ e )
{
   // Set FontMustExist to true, which causes message box error 
   // if the user enters a font that does not exist. 
   FontDialog1->FontMustExist = true;

   // Associate the method handling the Apply event with the event.
   FontDialog1->Apply += gcnew System::EventHandler( this, &Form1::FontDialog1_Apply );

   // Set a minimum and maximum size to be 
   // shown in the FontDialog.
   FontDialog1->MaxSize = 32;
   FontDialog1->MinSize = 18;

   // Show the Apply button in the dialog.
   FontDialog1->ShowApply = true;

   // Do not show effects such as Underline 
   // and Bold.
   FontDialog1->ShowEffects = false;

   // Save the existing font.
   System::Drawing::Font^ oldFont = this->Font;

   //Show the dialog, and get the result
   System::Windows::Forms::DialogResult result = FontDialog1->ShowDialog();

   // If the OK button in the Font dialog box is clicked,  
   // set all the controls' fonts to the chosen font by calling 
   // the FontDialog1_Apply method. 
   if ( result == ::DialogResult::OK )
   {
      FontDialog1_Apply( this->Button1, gcnew System::EventArgs );
   }
   // If Cancel is clicked, set the font back to 
   // the original font. 
   else 

   // If Cancel is clicked, set the font back to 
   // the original font. 
   if ( result == ::DialogResult::Cancel )
   {
      this->Font = oldFont;
      System::Collections::IEnumerator^ myEnum = this->Controls->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Control^ containedControl = safe_cast<Control^>(myEnum->Current);
         containedControl->Font = oldFont;
      }
   }
}


// Handle the Apply event by setting all controls' fonts to  
// the chosen font.  
void FontDialog1_Apply( Object^ sender, System::EventArgs^ e )
{
   this->Font = FontDialog1->Font;
   System::Collections::IEnumerator^ myEnum1 = this->Controls->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      Control^ containedControl = safe_cast<Control^>(myEnum1->Current);
      containedControl->Font = FontDialog1->Font;
   }
}
FontDialog.MaxSize, FontDialog.ShowEffects and FontDialog.FontMustExist members and handling the Apply event. To run this example paste the following code in a form 

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft