Getting Started with Windows Forms FontListBox
25 May 20237 minutes to read
This section briefly describes how to create a new Windows Forms project in Visual Studio and add the FontListBox with its basic functionalities.
Assembly deployment
Refer to the Control Dependencies section to get the list of assemblies or the details of NuGet package that needs to be added as reference to use the control in any application.
Refer to NuGet Packages to learn how to install nuget packages in a Windows Forms application.
Adding the FontListBox control via designer
The FontListBox control can be added via designer using the following steps:
-
Create a new Windows Forms application in Visual Studio.
-
Add the FontListBox control to an application by dragging it from the toolbox to design view. The following dependent assemblies will be added automatically:
- Syncfusion.Grid.Base
- Syncfusion.Grid.Windows
- Syncfusion.Shared.Base
- Syncfusion.Shared.Windows
- Syncfusion.Tools.Base
- Syncfusion.Tools.Windows
Adding the FontListBox control via code
The following steps describe how to create a FontListBox control programmatically:
-
Create C# or VB application via Visual Studio.
-
Add the following assembly references to the project:
- Syncfusion.Grid.Base
- Syncfusion.Grid.Windows
- Syncfusion.Shared.Base
- Syncfusion.Shared.Windows
- Syncfusion.Tools.Base
- Syncfusion.Tools.Windows
-
Include the required namespace.
using Syncfusion.Windows.Forms.Tools;
Imports Syncfusion.Windows.Forms.Tools
-
Create an instance of the FontListBox control, specify its size, and add it to the form.
FontListBox fontListBox1 = new FontListBox(); fontListBox1.Size = new System.Drawing.Size(160, 94); this.Controls.Add(fontListBox1);
Dim fontListBox1 As New FontListBox() fontListBox1.Size = New System.Drawing.Size(160, 94) Me.Controls.Add(fontListBox1)
Selected items
At run time, the items in the FontListBox can be selected. The text style will be changed based on the selected font item from the FontListBox.
// For the Label control.
Label label = new Label();
label.Anchor = System.Windows.Forms.AnchorStyles.None;
label.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
label.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F);
label.Location = new System.Drawing.Point(430, 83);
label.Size = new System.Drawing.Size(346, 95);
label.Text = "The FontListBox is a list box derived control that are automatically populated wi" +
"th the fonts installed on the user’s system. It provide an easy way to fill a li" +
"st box with system fonts.";
// Add the control.
this.Controls.Add(label);
// Add the selection event for control.
fontListBox1.SelectedIndexChanged += new System.EventHandler(this.FontListBox1_SelectedIndexChanged);
// Selection event for FontListBox
private void FontListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.label.Font = new System.Drawing.Font(this.fontListBox1.SelectedItem.ToString(), 10, System.Drawing.FontStyle.Regular);
}
' For the Label control.
Private label As New Label()
label.Anchor = System.Windows.Forms.AnchorStyles.None
label.FlatStyle = System.Windows.Forms.FlatStyle.Flat
label.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75F)
label.Location = New System.Drawing.Point(430, 83)
label.Size = New System.Drawing.Size(346, 95)
label.Text = "The FontListBox is a list box derived control that are automatically populated wi" & "th the fonts installed on the user’s system. It provide an easy way to fill a li" & "st box with system fonts."
' Add the control.
Me.Controls.Add(Me.label)
' Add the selection event for control.
AddHandler fontListBox1.SelectedIndexChanged, AddressOf FontListBox1_SelectedIndexChanged
' Selection event for FontListBox.
private void FontListBox1_SelectedIndexChanged(Object sender, System.EventArgs e)
Me.label.Font = New System.Drawing.Font(Me.fontListBox1.SelectedItem.ToString(), 10, System.Drawing.FontStyle.Regular)
Selection mode
At run time, the items in the FontListBox can be selected based on the selection mode specified in the SelectionMode property. Selection can be made using mouse and keyboard.
The following options are available in the FontListBox control.
SelectionMode | Description |
---|---|
None | No items can be selected. |
One | Only one item can be selected. |
MultiSimple | Multiple items can be selected. |
MultiExtended | Multiple items can be selected using the SHIFT, CTRL, and arrow keys to make selections. |
fontListBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
fontListBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended