VB.NET Font Dialog Box
The Font Dialog Box allows the user to select the font family, style, and size for the text in an application. However, a user can also select the font color and apply the current setting to the selected text of the control by clicking the Apply button.
Let's create a Font Dialog box in the VB.NET Windows form using the following steps.
Step 1. We need to drag the Font Dialog box from the toolbox and drop it to the Windows form, as shown below.
Step2: Once the Font Dialog is added to the form, we can set various properties of the Font by clicking on the Font Dialog box.
Properties of Font Dialog
There are following properties of the Font Dialog Box in the VB.NET.
|The ShowApply property sets a value representing whether you want to display the Apply button on the dialog box.
|The ShowEffects property is used to set various effects on the text such as strikethrough, text color, and underline options by setting values on the FontDialog box.
|The Font property is used to get or set the selected font to display changes.
|The Container property is used to get the IContainer that contains the Component of the Font Dialog Box.
|The AllowverticalFonts property is used to set or get a value that represents whether the Font dialog box displays the horizontal and vertical fonts or displays only horizontals fonts.
|The AllowScriptChange property is used to set a value that allows the user to change the character specified in the Script combo box to show a character set other than the currently displayed character.
|The ScriptOnly property is used to set a value that allows the user to select only the font, the character set of the symbol, and the ANSI character from the dialog box.
|The ShowHelp property is used to set a value representing whether the Help button should be displayed in the dialog box.
|The MaxSize property gets or sets a value that allows the user to select only the maximum point size character.
|It is used to initialize FontDialog by obtaining values.
Methods of Font Dialog
|The Equals() method is used to check whether the current or defined object is the same.
|It is used to call the HelpRequest event in the dialog box.
|The Reset() method is used to reset all changes to their default values.
|The Dispose() method is used to free all resources used by the Control or the component in the Dialog Box.
|It is used to override a derived class to create a common dialog box.
|The ShowDialog () method is used to run a common dialog box with the default setting.
|The CreateObjRef () method is used to create an object that contains all related information to initialize a proxy that can communicate with a remote object.
Events of Font Dialog
|When control or component is terminated by calling the Dispose() method, a Dispose event occurs.
|When a user clicks the Help button of the dialog box, the HelpRequest event is called.
|When a user clicks on the Apply button of the Font dialog box, an apply event occurs.
Let's create a simple program to display the Font dialog box in the VB.NET Windows Forms.
Write some text in TextArea, as shown below.
Select the string and click the 'Change Font' button; it opens the Font window. In the Font window, we can change the size, font, and font style of the selected string.
After setting the font, font style, size, and color, etc. on the Font dialog box, it shows the formatted string, as shown below.