Getting Started with Windows Forms FontComboBox

18 Nov 20185 minutes to read

This section explains how to get started with the Windows Forms FontComboBox control and its basic features.

Assembly Deployment

Refer to the Control dependencies section for the list of assemblies and NuGet packages required to use the FontComboBox control.

Refer to NuGet Packages to learn how to install NuGet packages in a Windows Forms application.

To install the required NuGet package using the NuGet Package Manager Console, run the following command:

Install-Package Syncfusion.Tools.Windows

Adding FontComboBox via Designer

  1. Create a new Windows Forms project in Visual Studio.

  2. Drag the FontComboBox control from the Toolbox and drop it onto the Windows Form designer. The following dependent assemblies are added automatically:

    • Syncfusion.Tools.Windows
    • Syncfusion.Shared.Base
    • Syncfusion.Tools.Base
    • Syncfusion.Grid.Base
    • Syncfusion.Shared.Windows
    • Syncfusion.Grid.Windows
    • Syncfusion.SpellChecker.Base

Drag and drop the FontComboBox control from Toolbox

Adding FontComboBox via Code

To add the FontComboBox control programmatically, follow these steps. Place the code in the form constructor or the form’s Load event handler.

  1. Add the following assembly references to the project:

    • Syncfusion.Tools.Windows
    • Syncfusion.Shared.Base
    • Syncfusion.Tools.Base
    • Syncfusion.Grid.Base
    • Syncfusion.Shared.Windows
    • Syncfusion.Grid.Windows
    • Syncfusion.SpellChecker.Base
  2. Include the Syncfusion.Windows.Forms.Tools namespace.

  3. Create an instance of the FontComboBox control and add it to the form.

    using System.Drawing;
    using System.Windows.Forms;
    using Syncfusion.Windows.Forms.Tools;
       
    public partial class Form1 : Form
    {
        private FontComboBox fontComboBox;
       
        public Form1()
        {
            InitializeComponent();
       
            fontComboBox = new FontComboBox();
            fontComboBox.Size = new Size(150, 40);
            fontComboBox.Location = new Point(100, 100);
            this.Controls.Add(fontComboBox);
        }
    }
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports Syncfusion.Windows.Forms.Tools
       
    Public Partial Class Form1
        Inherits Form
       
        Private fontComboBox As FontComboBox
       
        Public Sub New()
            InitializeComponent()
       
            fontComboBox = New FontComboBox()
            fontComboBox.Size = New Size(150, 40)
            fontComboBox.Location = New Point(100, 100)
            Me.Controls.Add(fontComboBox)
        End Sub
    End Class

Default initialization of WinForms FontComboBox control

AutoComplete

The font items displayed in the FontComboBox control can be filtered as you type by using the UseAutoComplete property. The default value is false. Set it to true to enable automatic completion based on the installed system fonts.

fontComboBox.UseAutoComplete = true;
fontComboBox.UseAutoComplete = True

Load the default font items in WinForms FontComboBox

Selection

You can select a font programmatically by using the SelectedItem or SelectedIndex property of the FontComboBox control. Use the SelectedItem property to select a font by name and the SelectedIndex property to select a font by its position in the list.

//Select the item using SelectedItem property.
fontComboBox.SelectedItem = "Arial";
//Select the index using SelectedIndex property.
fontComboBox.SelectedIndex = 1;
'Select the item using SelectedItem property.
fontComboBox.SelectedItem = "Arial"
'Select the index using SelectedIndex property.
fontComboBox.SelectedIndex = 1

Select the item using selection property

View sample in GitHub

RTL Support

By default, the FontComboBox control displays its content from left to right. Use the RightToLeft property to display the control content in right-to-left languages. Valid values are No, Yes, and Inherit.

fontComboBox.RightToLeft = RightToLeft.Yes;
fontComboBox.RightToLeft = RightToLeft.Yes

Change the control layout position in WinForms FontComboBox