Display a font selection dialog with an Apply button in C#
At either design time or run time, set the FontDialog's ShowApply property to true to make it display an Apply button. Then catch the dialog's Apply event and apply the currently selected font as shown in the following code.
// Apply the font.
private void fdFont_Apply(object sender, EventArgs e)
{
this.Font = fdFont.Font;
}
Display the dialog as usual but if the user doesn't click OK, restore the original font in case the program is displaying a preview of the font when the user closes the dialog.
// Display the dialog.
private void btnSelectFont_Click(object sender, EventArgs e)
{
// Save the original font.
Font original_font = this.Font;
// Initialize the dialog.
fdFont.Font = this.Font;
// Display the dialog and check the result.
if (fdFont.ShowDialog() == DialogResult.OK)
{
// Apply the selected font.
this.Font = fdFont.Font;
}
else
{
// Restore the original font.
this.Font = original_font;
}
}


Comments