syncfusion-winforms-fontcombobox

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implementing FontComboBox

实现FontComboBox

A specialized combo box control for Windows Forms that automatically populates with system fonts, providing an intuitive font selection interface with preview capabilities.
这是适用于Windows Forms的专用组合框控件,可自动填充系统字体,提供带有预览功能的直观字体选择界面。

When to Use This Skill

何时使用本技能

Use this skill when you need to:
  • Font Selection UI: Implement font picker controls in Windows Forms applications
  • System Font Display: Show all installed fonts with visual previews
  • Typography Tools: Build text editors, design tools, or formatting interfaces
  • Font Enumeration: Automatically populate dropdowns with available system fonts
  • Rich Text Applications: Create word processors, document editors, or formatting panels
  • Design Applications: Build UI customization tools requiring font selection
当你需要完成以下需求时可使用本技能:
  • 字体选择UI:在Windows Forms应用中实现字体选择器控件
  • 系统字体展示:展示所有已安装字体并提供可视化预览
  • 排版工具:构建文本编辑器、设计工具或格式化界面
  • 字体枚举:自动用可用的系统字体填充下拉列表
  • 富文本应用:开发文字处理器、文档编辑器或格式化面板
  • 设计类应用:构建需要字体选择功能的UI自定义工具

Component Overview

组件概述

The FontComboBox is a specialized combo box control derived from standard ComboBox that:
  • Automatically populates with all system-installed fonts
  • Displays font names in their respective typefaces
  • Supports AutoComplete for quick font search
  • Provides extensive dropdown customization options
  • Includes built-in visual styles and theming
  • Handles font selection events with type-safe access
Key Capabilities:
  • Automatic system font loading
  • Font preview in dropdown items
  • AutoComplete and filtering
  • Multiple visual themes (Office2016, Metro, Office2007)
  • RTL support
  • Symbol font rendering
  • Custom event handling
FontComboBox 是派生自标准ComboBox的专用组合框控件,具备以下特性:
  • 自动填充所有系统已安装字体
  • 用字体本身的样式显示字体名称
  • 支持AutoComplete实现快速字体搜索
  • 提供丰富的下拉列表自定义选项
  • 内置多种视觉样式和主题
  • 支持类型安全的字体选择事件处理
核心功能:
  • 自动加载系统字体
  • 下拉项内的字体预览
  • AutoComplete与筛选能力
  • 多种视觉主题(Office2016、Metro、Office2007)
  • RTL(从右到左)布局支持
  • 符号字体渲染
  • 自定义事件处理

Documentation and Navigation Guide

文档与导航指南

Getting Started

入门指南

📄 Read: references/getting-started.md
When to read: Starting new implementation, setting up dependencies, first-time usage
Topics covered:
  • Assembly deployment and NuGet packages
  • Control dependencies for FontComboBox
  • Adding via Visual Studio designer (toolbox drag-drop)
  • Adding via code (manual instantiation)
  • Basic initialization and configuration
  • RTL (Right-to-Left) layout support
  • Sample GitHub projects

📄 阅读: references/getting-started.md
适用场景: 新功能开发、依赖配置、首次使用该控件
涵盖主题:
  • 程序集部署与NuGet包
  • FontComboBox的控件依赖
  • 通过Visual Studio设计器添加(工具箱拖拽)
  • 通过代码添加(手动实例化)
  • 基础初始化与配置
  • RTL(从右到左)布局支持
  • GitHub示例项目

AutoComplete Features

AutoComplete特性

📄 Read: references/autocomplete.md
When to read: Enabling font search, implementing type-ahead, configuring auto-completion behavior
Topics covered:
  • UseAutoComplete property for enabling/disabling
  • AutoCompleteSource options (ListItems, CustomSource)
  • AutoCompleteMode settings (Suggest, Append, SuggestAppend)
  • AutoCompleteCustomSource for custom font lists
  • Best practices for AutoComplete configuration
  • Code examples with filtering behavior

📄 阅读: references/autocomplete.md
适用场景: 启用字体搜索、实现键入提示、配置自动补全行为
涵盖主题:
  • 用UseAutoComplete属性启用/禁用功能
  • AutoCompleteSource选项(ListItems、CustomSource)
  • AutoCompleteMode设置(Suggest、Append、SuggestAppend)
  • 自定义字体列表的AutoCompleteCustomSource配置
  • AutoComplete配置最佳实践
  • 筛选行为的代码示例

DropDown Configuration

下拉列表配置

📄 Read: references/dropdown-configuration.md
When to read: Customizing dropdown appearance, controlling popup behavior, configuring item display
Topics covered:
  • DropDownStyle options (DropDown, DropDownList, Simple)
  • DropDownHeight and DropDownWidth sizing
  • MaxDropDownItems for visible item count
  • ShowSymbolFontPreview for symbol fonts
  • ItemHeight for item spacing
  • Sorted property for alphabetical ordering
  • Dropdown behavior customization

📄 阅读: references/dropdown-configuration.md
适用场景: 自定义下拉列表外观、控制弹出行为、配置项展示规则
涵盖主题:
  • DropDownStyle选项(DropDown、DropDownList、Simple)
  • DropDownHeight和DropDownWidth尺寸设置
  • 控制可见项数量的MaxDropDownItems
  • 符号字体展示的ShowSymbolFontPreview
  • 控制项间距的ItemHeight
  • 字母排序的Sorted属性
  • 下拉列表行为自定义

Selection and Events

选择与事件

📄 Read: references/selection-and-events.md
When to read: Handling font selection changes, responding to user input, applying selected fonts
Topics covered:
  • Programmatic selection with SelectedItem and SelectedIndex
  • SelectedIndexChanged event handling
  • Custom FontSelected event implementation
  • Applying selected fonts to other controls (labels, textboxes)
  • Event-driven font updates
  • Code patterns for selection management

📄 阅读: references/selection-and-events.md
适用场景: 处理字体选择变更、响应用户输入、应用选中的字体
涵盖主题:
  • 用SelectedItem和SelectedIndex实现编程式选择
  • SelectedIndexChanged事件处理
  • 自定义FontSelected事件实现
  • 将选中字体应用到其他控件(标签、文本框)
  • 事件驱动的字体更新
  • 选择管理的代码模式

Visual Styles and Theming

视觉样式与主题

📄 Read: references/visual-styles.md
When to read: Applying themes, customizing control appearance, matching application design
Topics covered:
  • VisualStyle property (Office2016Colorful, Office2016White, Office2016Black, Office2016DarkGray, Metro, Office2010, Office2007, Default)
  • Office2007ColorScheme options (Blue, Silver, Black)
  • Custom color themes with Office2007ColorTheme.Managed
  • ApplyManagedColors for custom color application
  • Theme screenshots and visual examples

📄 阅读: references/visual-styles.md
适用场景: 应用主题、自定义控件外观、匹配应用设计规范
涵盖主题:
  • VisualStyle属性(Office2016Colorful、Office2016White、Office2016Black、Office2016DarkGray、Metro、Office2010、Office2007、Default)
  • Office2007ColorScheme选项(Blue、Silver、Black)
  • 用Office2007ColorTheme.Managed自定义颜色主题
  • 用ApplyManagedColors应用自定义颜色
  • 主题截图与可视化示例

Quick Start

快速开始

Basic FontComboBox Setup

基础FontComboBox配置

csharp
using Syncfusion.Windows.Forms.Tools;

// Create and configure FontComboBox
FontComboBox fontComboBox = new FontComboBox();
fontComboBox.Size = new Size(200, 25);
fontComboBox.Location = new Point(20, 20);

// Enable AutoComplete for font search
fontComboBox.UseAutoComplete = true;

// Set default selected font
fontComboBox.SelectedItem = "Arial";

// Add to form
this.Controls.Add(fontComboBox);
csharp
using Syncfusion.Windows.Forms.Tools;

// 创建并配置FontComboBox
FontComboBox fontComboBox = new FontComboBox();
fontComboBox.Size = new Size(200, 25);
fontComboBox.Location = new Point(20, 20);

// 启用AutoComplete实现字体搜索
fontComboBox.UseAutoComplete = true;

// 设置默认选中字体
fontComboBox.SelectedItem = "Arial";

// 添加到窗体
this.Controls.Add(fontComboBox);

Handle Font Selection

处理字体选择

csharp
// Subscribe to selection changed event
fontComboBox.SelectedIndexChanged += FontComboBox_SelectedIndexChanged;

private void FontComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    if (fontComboBox.SelectedItem != null)
    {
        // Apply selected font to a label
        label1.Font = new Font(fontComboBox.SelectedItem.ToString(), 12, FontStyle.Regular);
    }
}
csharp
// 订阅选择变更事件
fontComboBox.SelectedIndexChanged += FontComboBox_SelectedIndexChanged;

private void FontComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    if (fontComboBox.SelectedItem != null)
    {
        // 将选中字体应用到标签
        label1.Font = new Font(fontComboBox.SelectedItem.ToString(), 12, FontStyle.Regular);
    }
}

Common Patterns

常用模式

Pattern 1: Font Picker with Preview

模式1:带预览的字体选择器

csharp
// Configure FontComboBox with preview
FontComboBox fontComboBox = new FontComboBox
{
    UseAutoComplete = true,
    DropDownStyle = ComboBoxStyle.DropDownList,
    ShowSymbolFontPreview = true,
    DropDownHeight = 200,
    Sorted = true
};

// Handle selection to update preview label
fontComboBox.SelectedIndexChanged += (s, e) =>
{
    if (fontComboBox.SelectedItem != null)
    {
        previewLabel.Font = new Font(fontComboBox.SelectedItem.ToString(), 14);
        previewLabel.Text = "The quick brown fox jumps over the lazy dog";
    }
};
csharp
// 配置带预览的FontComboBox
FontComboBox fontComboBox = new FontComboBox
{
    UseAutoComplete = true,
    DropDownStyle = ComboBoxStyle.DropDownList,
    ShowSymbolFontPreview = true,
    DropDownHeight = 200,
    Sorted = true
};

// 处理选择事件更新预览标签
fontComboBox.SelectedIndexChanged += (s, e) =>
{
    if (fontComboBox.SelectedItem != null)
    {
        previewLabel.Font = new Font(fontComboBox.SelectedItem.ToString(), 14);
        previewLabel.Text = "The quick brown fox jumps over the lazy dog";
    }
};

Pattern 2: Themed Font Selector

模式2:带主题的字体选择器

csharp
// Apply Office2016 theme
FontComboBox fontComboBox = new FontComboBox
{
    VisualStyle = ThemedComboBoxStyles.Office2016Colorful,
    UseAutoComplete = true,
    DropDownStyle = ComboBoxStyle.DropDown
};

// Set initial font
fontComboBox.SelectedItem = "Segoe UI";
csharp
// 应用Office2016主题
FontComboBox fontComboBox = new FontComboBox
{
    VisualStyle = ThemedComboBoxStyles.Office2016Colorful,
    UseAutoComplete = true,
    DropDownStyle = ComboBoxStyle.DropDown
};

// 设置初始字体
fontComboBox.SelectedItem = "Segoe UI";

Pattern 3: Custom Font List with AutoComplete

模式3:带AutoComplete的自定义字体列表

csharp
// Create FontComboBox with custom font list
FontComboBox fontComboBox = new FontComboBox();

// Configure custom AutoComplete source
fontComboBox.AutoCompleteCustomSource.AddRange(new string[] 
{
    "Arial", "Calibri", "Cambria", "Georgia", "Times New Roman", "Verdana"
});
fontComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
fontComboBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
csharp
// 创建带自定义字体列表的FontComboBox
FontComboBox fontComboBox = new FontComboBox();

// 配置自定义AutoComplete源
fontComboBox.AutoCompleteCustomSource.AddRange(new string[] 
{
    "Arial", "Calibri", "Cambria", "Georgia", "Times New Roman", "Verdana"
});
fontComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
fontComboBox.AutoCompleteSource = AutoCompleteSource.CustomSource;

Key Properties

核心属性

Selection Properties

选择相关属性

  • SelectedItem: Gets or sets the currently selected font name (string)
  • SelectedIndex: Gets or sets the index of the selected font (int)
  • SelectedItem:获取或设置当前选中的字体名称(字符串类型)
  • SelectedIndex:获取或设置选中字体的索引(整数类型)

AutoComplete Properties

AutoComplete相关属性

  • UseAutoComplete: Enables/disables AutoComplete feature (bool)
  • AutoCompleteMode: Sets completion behavior (Suggest, Append, SuggestAppend)
  • AutoCompleteSource: Specifies source for completion (ListItems, CustomSource)
  • AutoCompleteCustomSource: Custom string collection for AutoComplete
  • UseAutoComplete:启用/禁用AutoComplete功能(布尔类型)
  • AutoCompleteMode:设置补全行为(Suggest、Append、SuggestAppend)
  • AutoCompleteSource:指定补全的数据源(ListItems、CustomSource)
  • AutoCompleteCustomSource:AutoComplete的自定义字符串集合

DropDown Properties

下拉列表相关属性

  • DropDownStyle: Controls edit/select behavior (DropDown, DropDownList, Simple)
  • DropDownHeight: Height of dropdown in pixels (int)
  • DropDownWidth: Width of dropdown in pixels (int)
  • MaxDropDownItems: Maximum visible items in dropdown (int)
  • ShowSymbolFontPreview: Renders symbol fonts with their typeface (bool)
  • DropDownStyle:控制编辑/选择行为(DropDown、DropDownList、Simple)
  • DropDownHeight:下拉列表的高度(单位:像素,整数类型)
  • DropDownWidth:下拉列表的宽度(单位:像素,整数类型)
  • MaxDropDownItems:下拉列表最大可见项数(整数类型)
  • ShowSymbolFontPreview:用符号字体本身的样式渲染符号字体(布尔类型)

Item Properties

列表项相关属性

  • ItemHeight: Height of each dropdown item in pixels (int)
  • Sorted: Enables alphabetical sorting of fonts (bool)
  • ItemHeight:每个下拉项的高度(单位:像素,整数类型)
  • Sorted:启用字体的字母排序功能(布尔类型)

Styling Properties

样式相关属性

  • VisualStyle: Sets control theme (Office2016Colorful, Metro, Office2007, etc.)
  • Office2007ColorScheme: Color scheme for Office2007 style (Blue, Silver, Black)
  • Office2007ColorTheme: Custom theme mode (Managed for custom colors)
  • VisualStyle:设置控件主题(Office2016Colorful、Metro、Office2007等)
  • Office2007ColorScheme:Office2007风格的配色方案(Blue、Silver、Black)
  • Office2007ColorTheme:自定义主题模式(Managed表示使用自定义颜色)

Layout Properties

布局相关属性

  • RightToLeft: Enables RTL layout (RightToLeft.Yes/No)
  • RightToLeft:启用RTL布局(RightToLeft.Yes/No)

Common Use Cases

常见使用场景

Rich Text Editor Font Selector

富文本编辑器字体选择器

Build a font picker for text formatting toolbars in document editors, word processors, or email clients.
为文档编辑器、文字处理器或邮件客户端的文本格式化工具栏构建字体选择器。

Design Tool Typography Panel

设计工具排版面板

Implement font selection in graphic design applications, presentation software, or UI builders.
在图形设计应用、演示软件或UI构建工具中实现字体选择功能。

Application Settings Font Configuration

应用设置字体配置

Create font preferences dialogs for applications with customizable text display.
为支持自定义文本显示的应用开发字体偏好设置对话框。

Custom Control Property Editors

自定义控件属性编辑器

Build property grids or configuration panels where users select fonts for custom controls.
构建属性网格或配置面板,支持用户为自定义控件选择字体。

Font Comparison Tools

字体对比工具

Develop utilities for comparing fonts side-by-side with live previews.
开发支持实时预览的字体并排对比工具。

Related Skills

相关技能

  • AutoComplete - General AutoComplete control implementation
  • ComboBox - Base ComboBox control patterns
  • AutoComplete - 通用AutoComplete控件实现
  • ComboBox - 基础ComboBox控件模式

Notes

注意事项

  • FontComboBox automatically loads all system-installed fonts - no manual population required
  • Symbol fonts can be displayed with their actual glyphs using ShowSymbolFontPreview
  • Use DropDownList style to prevent manual text entry, allowing only font selection
  • SelectedIndexChanged fires whenever selection changes programmatically or by user
  • Control inherits from standard ComboBox, so all base properties/events are available
  • FontComboBox会自动加载所有系统已安装字体,无需手动填充
  • 开启ShowSymbolFontPreview即可用符号字体本身的字形展示符号字体
  • 使用DropDownList样式可禁止手动输入,仅允许选择字体
  • 无论是编程修改还是用户操作导致选择变更,都会触发SelectedIndexChanged事件
  • 控件继承自标准ComboBox,因此所有基础属性/事件都可以使用