FontDialog Controller in Visual Basic .Net
Last Updated: March 19, 2020
FontDialog Controller in VB.NET can be used to change Fonts in your application. So user can select the Font Type,Size,Color etc
You can see the FontDialog control on the Dialogs section of the ToolBox. You can drag and drop this control to the form
Now We will try to implement following Form
When you open the FontDialog and select font and other properties it will apply the changes to TextBox
So this is the code for opening dialog and applying changes for fonts
Public Class Form1 Private Sub ButtonOpen_Click(sender As Object, e As EventArgs) Handles ButtonOpen.Click FontDialog1.ShowColor = True If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then TextBox1.Font = FontDialog1.Font TextBox1.ForeColor = FontDialog1.Color End If End Sub End Class
Code explanation
- Line 5 : ShowColor property is to show the colors in FontDialog
- Line 7 : Check ShowDialog result with Windows.Forms.DialogResult.OK
- Line 8 : Assign Font value to Font property of the
TextBox
- Line 9 : Assign Color value to ForeColor property of the
TextBox