FontDialog in C#

In this article, we will learn how to use font dialog box in windows form in C#.

Let's create windows form.

Step 1
In Visual Studio select "File" = > "New" = > "Project..." then select C# Windows Forms Application then click Ok.

create windows form

Step 2
Let's create a FontDialog then you go "View" = > select "ToolBox" (Crtl+Alt+X) = > then select "All Windows Forms" = > Choose "FontDialog".

font dialog
  1. First of all, we'll know about the "FontDialog".

    font dialog are mainly used in any text font style change in c#. We'll discuss about properties and function and events of font dialog write down.

    The following code snippet creates a FontDialog control object under btnsave "OnClick" methods.

    FontDialog fontdialog = new FontDialog();
    

    ShowDialog() method displays the fontdialog box.

    fontdialog.ShowDialog();
    

    Dispose() method released all resources in fontdialog box.

    fontdialog.Dispose();
    

    Reset() methods resets all dialog box options to their default values.

    fontdialog.Reset();
    

    Font properties are used to get or sets fontdialog box selected font.

    fontdialog.Font;
    

    Color properties are used to get or sets fontdialog box font color.

    fontdialog.AllowSimulations = true;
    

    FontMustExist properties are used to get or sets a value indicating whether the dialog box specifies an error condition if the user attempt to select a style or font that does not exist.

    fontdialog.FontMustExist = true;
    

    MaxSize properties are used to get or sets the maximum point size a user can select.

    fontdialog.MaxSize = 24;
    

    MinSize properties are used to get or sets the minimum point size a user can select.

    fontdialog.MinSize = 10;
    

    ShowEffects properties are used to gets or sets a value indicating whether the dialog box contains control that allow the user to specify strikethrough,underline and text color options.

    fontdialog.ShowEffects = false;
    


Write a comment


Name Email Message