syncfusion-winforms-theming
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWindows Forms Theming (SkinManager)
Windows Forms 主题设置(SkinManager)
The Syncfusion Windows Forms SkinManager provides support to apply consistent themes across all Syncfusion controls in an application. It enables uniform styling for entire applications, forms, or individual controls using predefined themes or custom Theme Studio-based themes.
Syncfusion Windows Forms SkinManager 支持为应用内所有 Syncfusion 控件应用统一的主题。你可以使用预设主题或基于 Theme Studio 的自定义主题,为整个应用、单个窗体或独立控件设置一致的样式。
When to Use This Skill
何时使用本指南
Use this skill when you need to:
- Apply themes to Syncfusion WinForms controls (Office2007, Office2010, Office2013, Office2016, Office2019, Metro)
- Set up theme assemblies and load them properly
- Apply themes to entire applications, forms, or containers
- Customize theme appearance using ThemeStyle or Style properties
- Apply themes through designer or code-based approaches
- Control whether themes override user customizations
当你需要完成以下操作时可参考本指南:
- 为 Syncfusion WinForms 控件应用主题(Office2007、Office2010、Office2013、Office2016、Office2019、Metro)
- 配置主题程序集并正确加载
- 为整个应用、窗体或容器应用主题
- 使用 ThemeStyle 或 Style 属性自定义主题外观
- 通过设计器或代码方式应用主题
- 控制主题是否覆盖用户自定义样式
Component Overview
组件概览
SkinManager is a component that manages theme application for Syncfusion Windows Forms controls. It supports:
- Multiple predefined themes (Office2007, Office2010, Office2013, Office2016, Office2019, Metro, HighContrast)
- Application-wide theme management
- Form/container-level theme application
- Individual control theme application
- Advanced styling through ThemeStyle/Style properties
Key Assembly:
Syncfusion.Shared.BaseAdditional Assemblies: Some themes require separate assemblies (Office2016Theme, Office2019Theme, HighContrastTheme)
SkinManager 是负责为 Syncfusion Windows Forms 控件管理主题应用的组件,支持以下能力:
- 多款预设主题(Office2007、Office2010、Office2013、Office2016、Office2019、Metro、HighContrast)
- 应用全局主题管理
- 窗体/容器层级的主题应用
- 单个控件的主题应用
- 通过 ThemeStyle/Style 属性实现高级样式定制
核心程序集:
Syncfusion.Shared.Base额外程序集: 部分主题需要单独引用对应程序集(Office2016Theme、Office2019Theme、HighContrastTheme)
Documentation and Navigation Guide
文档与导航指南
Getting Started
入门指南
📄 Read: references/getting-started.md
- Assembly deployment and theme assembly requirements
- Loading theme assemblies using LoadAssembly method
- Adding SkinManager component through designer
- Adding SkinManager component through code
- Basic theme application to controls and forms
- Applying themes to entire forms and containers
📄 阅读: references/getting-started.md
- 程序集部署与主题程序集要求
- 使用 LoadAssembly 方法加载主题程序集
- 通过设计器添加 SkinManager 组件
- 通过代码添加 SkinManager 组件
- 为控件和窗体应用基础主题
- 为整个窗体和容器应用主题
Theme Management
主题管理
📄 Read: references/theme-management.md
- Complete list of available themes
- VisualTheme property usage
- SetVisualTheme method for programmatic theme setting
- Application-wide theming using ApplicationVisualTheme
- Individual control theming using ThemeName property
- Assembly requirements for specific themes
- Theme application patterns and best practices
📄 阅读: references/theme-management.md
- 可用主题完整列表
- VisualTheme 属性使用方法
- 使用 SetVisualTheme 方法通过代码设置主题
- 使用 ApplicationVisualTheme 配置应用全局主题
- 使用 ThemeName 属性为单个控件设置主题
- 特定主题的程序集要求
- 主题应用模式与最佳实践
Advanced Customization
高级自定义
📄 Read: references/advanced-customization.md
- ThemeStyle property for theme customization
- Style property for Sf-prefixed controls
- CanOverrideStyle property behavior
- FontHelper customization for application-wide fonts
- Custom styling examples and patterns
- Overriding user customizations with themes
📄 阅读: references/advanced-customization.md
- 用于主题自定义的 ThemeStyle 属性
- 适用于 Sf 前缀控件的 Style 属性
- CanOverrideStyle 属性的行为说明
- 用于配置应用全局字体的 FontHelper 自定义
- 自定义样式示例与模式
- 用主题覆盖用户自定义样式
Quick Start Example
快速上手示例
Basic Theme Application (Code-Based)
基础主题应用(代码方式)
csharp
using Syncfusion.Windows.Forms;
namespace MyWinFormsApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Create SkinManager instance
SkinManager skinManager1 = new SkinManager(this.components);
// Apply theme to entire form (all Syncfusion controls)
skinManager1.Controls = this;
skinManager1.VisualTheme = VisualTheme.Office2016Black;
}
}
}csharp
using Syncfusion.Windows.Forms;
namespace MyWinFormsApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Create SkinManager instance
SkinManager skinManager1 = new SkinManager(this.components);
// Apply theme to entire form (all Syncfusion controls)
skinManager1.Controls = this;
skinManager1.VisualTheme = VisualTheme.Office2016Black;
}
}
}Application-Wide Theme (Program.cs)
应用全局主题(Program.cs)
csharp
using Syncfusion.Windows.Forms;
using Syncfusion.WinForms.Themes;
static class Program
{
[STAThread]
static void Main()
{
// Load theme assembly (for Office2019, Office2016, HighContrast)
SkinManager.LoadAssembly(typeof(Office2019Theme).Assembly);
// Set application-wide theme
SkinManager.ApplicationVisualTheme = "Office2019Colorful";
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}csharp
using Syncfusion.Windows.Forms;
using Syncfusion.WinForms.Themes;
static class Program
{
[STAThread]
static void Main()
{
// Load theme assembly (for Office2019, Office2016, HighContrast)
SkinManager.LoadAssembly(typeof(Office2019Theme).Assembly);
// Set application-wide theme
SkinManager.ApplicationVisualTheme = "Office2019Colorful";
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}Common Patterns
常用模式
Pattern 1: Theme Entire Form
模式1:为整个窗体设置主题
csharp
// Apply theme to all Syncfusion controls in a form
SkinManager skinManager1 = new SkinManager(this.components);
skinManager1.Controls = this; // 'this' refers to the form
skinManager1.VisualTheme = VisualTheme.Office2016White;csharp
// Apply theme to all Syncfusion controls in a form
SkinManager skinManager1 = new SkinManager(this.components);
skinManager1.Controls = this; // 'this' refers to the form
skinManager1.VisualTheme = VisualTheme.Office2016White;Pattern 2: Theme Individual Control
模式2:为单个控件设置主题
csharp
// Option 1: Using SkinManager
skinManager1.Controls = treeViewAdv1;
skinManager1.VisualTheme = VisualTheme.Office2016Colorful;
// Option 2: Using ThemeName property
this.treeViewAdv1.ThemeName = "Office2019Colorful";csharp
// Option 1: Using SkinManager
skinManager1.Controls = treeViewAdv1;
skinManager1.VisualTheme = VisualTheme.Office2016Colorful;
// Option 2: Using ThemeName property
this.treeViewAdv1.ThemeName = "Office2019Colorful";Pattern 3: Loading Required Theme Assemblies
模式3:加载所需的主题程序集
csharp
// Office2019 themes
SkinManager.LoadAssembly(typeof(Office2019Theme).Assembly);
// Office2016 themes (for SfDataGrid, SfButton, etc.)
SkinManager.LoadAssembly(typeof(Syncfusion.WinForms.Themes.Office2016Theme).Assembly);
// HighContrast themes
SkinManager.LoadAssembly(typeof(HighContrastTheme).Assembly);csharp
// Office2019 themes
SkinManager.LoadAssembly(typeof(Office2019Theme).Assembly);
// Office2016 themes (for SfDataGrid, SfButton, etc.)
SkinManager.LoadAssembly(typeof(Syncfusion.WinForms.Themes.Office2016Theme).Assembly);
// HighContrast themes
SkinManager.LoadAssembly(typeof(HighContrastTheme).Assembly);Pattern 4: Customize Theme Appearance
模式4:自定义主题外观
csharp
// For Theme Studio themes, customize using ThemeStyle
this.treeViewAdv1.ThemeName = "Office2019Colorful";
this.treeViewAdv1.ThemeStyle.BackColor = System.Drawing.Color.White;
this.treeViewAdv1.ThemeStyle.BorderColor = System.Drawing.Color.SteelBlue;
this.treeViewAdv1.ThemeStyle.TreeNodeAdvStyle.TextColor = System.Drawing.Color.Red;csharp
// For Theme Studio themes, customize using ThemeStyle
this.treeViewAdv1.ThemeName = "Office2019Colorful";
this.treeViewAdv1.ThemeStyle.BackColor = System.Drawing.Color.White;
this.treeViewAdv1.ThemeStyle.BorderColor = System.Drawing.Color.SteelBlue;
this.treeViewAdv1.ThemeStyle.TreeNodeAdvStyle.TextColor = System.Drawing.Color.Red;Key Properties and Methods
核心属性与方法
SkinManager Properties
SkinManager 属性
| Property | Description | Type |
|---|---|---|
| Specifies the parent control/form for which theme is applied | Control |
| Specifies the theme style to apply | Enum (VisualTheme) |
| Sets theme for entire application (static property) | String |
| 属性 | 说明 | 类型 |
|---|---|---|
| 指定要应用主题的父控件/窗体 | Control |
| 指定要应用的主题样式 | 枚举(VisualTheme) |
| 为整个应用设置主题(静态属性) | String |
SkinManager Methods
SkinManager 方法
| Method | Description | Parameters |
|---|---|---|
| Applies theme to specified control | Control, VisualTheme enum |
| Applies theme to specified control | Control, theme name string |
| Loads theme assembly before applying theme | Assembly object |
| 方法 | 说明 | 参数 |
|---|---|---|
| 为指定控件应用主题 | Control, VisualTheme 枚举 |
| 为指定控件应用主题 | Control, 主题名称字符串 |
| 在应用主题前加载主题程序集 | Assembly 对象 |
Control-Level Properties
控件层级属性
| Property | Description | Available On |
|---|---|---|
| Theme name to apply to individual control | All Syncfusion controls |
| Customize theme appearance properties | Non-Sf controls |
| Customize theme appearance properties | Sf-prefixed controls |
| Allow theme to override user customizations | Theme Studio compatible controls |
| 属性 | 说明 | 适用范围 |
|---|---|---|
| 应用到单个控件的主题名称 | 所有 Syncfusion 控件 |
| 自定义主题外观属性 | 非 Sf 前缀控件 |
| 自定义主题外观属性 | Sf 前缀控件 |
| 允许主题覆盖用户自定义样式 | 兼容 Theme Studio 的控件 |
Available Themes
可用主题
Predefined Themes (Built-in)
预设主题(内置)
- Office2007: Blue, Black, Silver, Managed
- Office2010: Blue, Black, Silver, Managed
- Office2013: White, Dark Gray, Black, Colorful
- Metro
- Office2007:Blue、Black、Silver、Managed
- Office2010:Blue、Black、Silver、Managed
- Office2013:White、Dark Gray、Black、Colorful
- Metro
Separate Assembly Themes
需单独引用程序集的主题
- Office2016: White, Dark Gray, Black, Colorful (requires )
Syncfusion.Office2016Theme.WinForms.dll - Office2019: Colorful (requires )
Syncfusion.Office2019Theme.WinForms.dll - HighContrast: Black (requires )
Syncfusion.HighContrastTheme.WinForms.dll
- Office2016:White、Dark Gray、Black、Colorful(需引用 )
Syncfusion.Office2016Theme.WinForms.dll - Office2019:Colorful(需引用 )
Syncfusion.Office2019Theme.WinForms.dll - HighContrast:Black(需引用 )
Syncfusion.HighContrastTheme.WinForms.dll
Common Use Cases
常见使用场景
- Uniform Application Styling: Apply consistent theme across all forms and controls
- Modern UI Appearance: Use Office2016/2019 themes for contemporary look
- Dark Mode Support: Implement dark themes (Office2016Black, Office2016DarkGray)
- Accessibility Compliance: Use HighContrast themes for accessibility
- Dynamic Theme Switching: Change themes at runtime based on user preferences
- Per-Form Theming: Apply different themes to different forms in the same application
- 统一应用样式:为所有窗体和控件应用一致的主题
- 现代化UI外观:使用 Office2016/2019 主题实现现代观感
- 深色模式支持:实现深色主题(Office2016Black、Office2016DarkGray)
- 无障碍合规:使用高对比度主题满足无障碍要求
- 动态主题切换:运行时根据用户偏好更改主题
- 单窗体主题设置:同一应用内为不同窗体应用不同主题
Important Notes
重要注意事项
- Assembly Loading: Always call before applying themes that require separate assemblies
LoadAssembly() - Application-Wide Theme: Set before main form initialization (in Program.cs)
ApplicationVisualTheme - Container Theming: Apply theme to form/container instead of individual controls for efficiency
- Override Behavior: Themes respect property to control customization overrides
CanOverrideStyle
- 程序集加载:应用需要单独程序集的主题前,务必先调用
LoadAssembly() - 应用全局主题:在主窗体初始化前(Program.cs 中)设置
ApplicationVisualTheme - 容器主题设置:优先为窗体/容器应用主题,而非逐个设置控件,提升效率
- 覆盖行为:主题会遵循 属性的设置来控制是否覆盖自定义样式
CanOverrideStyle
Troubleshooting
问题排查
Theme not applying:
- Verify theme assembly is loaded using
LoadAssembly() - Check that property is set correctly
Controls - Ensure theme name spelling is exact (case-sensitive)
Custom theme not working:
- Confirm custom theme assembly is referenced in project
- Verify is called before theme application
LoadAssembly() - Check that theme name matches assembly name exactly
Appearance customization not taking effect:
- Verify using Theme Studio-based themes (Office2019Colorful, HighContrastBlack)
- Check is set to
CanOverrideStyleif you want to preserve customizationsfalse - Use for non-Sf controls,
ThemeStylefor Sf-prefixed controlsStyle
主题未生效:
- 确认已通过 加载了对应的主题程序集
LoadAssembly() - 检查 属性是否设置正确
Controls - 确保主题名称拼写完全正确(区分大小写)
自定义主题不生效:
- 确认项目中已引用自定义主题程序集
- 验证在应用主题前已调用
LoadAssembly() - 检查主题名称与程序集名称完全匹配
外观自定义未生效:
- 确认使用的是基于 Theme Studio 的主题(Office2019Colorful、HighContrastBlack)
- 如果要保留自定义样式,检查 是否设置为
CanOverrideStylefalse - 非 Sf 前缀控件使用 ,Sf 前缀控件使用
ThemeStyleStyle