mcpField
S
syncfusion-winforms-gradient-label

syncfusion-winforms-gradient-label

github.com/syncfusion设计与 UI277 次安装1 周前更新
代码仓库

关于 syncfusion-winforms-gradient-label

此技能介绍 Syncfusion 的 Windows Forms GradientLabel 增强标签控件,适用于需要自定义标签背景和边框的界面开发。它支持多种渐变与图案、边框样式,并可将渐变设置序列化为 XML。

主要功能

  1. 01多种渐变和图案背景
  2. 02多色渐变设置
  3. 03自定义二维与三维边框
  4. 04控制文字外观和对齐
  5. 05XML 保存与加载渐变设置

适用场景

  1. 01设计表单分区标题
  2. 02制作仪表板信息和状态标签
  3. 03创建品牌配色标签
  4. 04保存并复用主题标签样式

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/syncfusion/winforms-ui-components-skills --skill syncfusion-winforms-gradient-label

安装后在 Claude Code 中输入/syncfusion-winforms-gradient-label确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
background-styling.md
border-configuration.md
foreground-text-settings.md
getting-started.md
serialization.md

详细介绍

实现 GradientLabel

一个增强型 Windows Forms 标签控件,提供渐变背景、美观的阴影、自定义边框和视觉样式功能,用于创建吸引人的 UI 标签。

何时使用此技能

在以下情况下使用此技能:

  • 渐变标签:创建具有渐变背景和颜色过渡的标签
  • 装饰性标题:设计视觉效果出众的分区标题和标题
  • 文本样式显示:实现带有自定义阴影和边框的精美标签
  • UI 增强:为窗体标签和描述性文本增添视觉吸引力
  • 自定义品牌标识:创建采用特定配色方案的品牌标签
  • 信息面板:构建带有背景效果的美观信息标签

组件概述

GradientLabel 是一种增强型标签控件,派生自标准 Windows Forms Label,并提供:

  • 多种渐变样式(Horizontal、Vertical、Diagonal、PathRectangle、PathEllipse)
  • 纯色和图案背景选项
  • 可自定义的 3D 和 2D 边框
  • 多色渐变支持
  • 用于状态持久化的 XML 序列化
  • 与标准 Label 功能完全兼容

主要功能:

  • 使用 BrushInfo 类设置渐变背景
  • 提供 6 种渐变样式,呈现不同视觉效果
  • 支持多种样式的图案背景
  • 自定义边框(边、样式、颜色)
  • 控制文本外观,包括禁用状态
  • 将渐变设置保存到 XML 或从 XML 加载
  • 继承所有标准 Label 功能(文本、字体、对齐方式)

文档和导航指南

快速入门

📄 阅读: references/getting-started.md

阅读时机: 开始新实现、设置依赖项、首次使用时

涵盖主题:

  • 程序集部署和 NuGet 包
  • GradientLabel 控件依赖项
  • 通过 Visual Studio 设计器添加(从工具箱拖放)
  • 通过代码添加(手动实例化)
  • 基本初始化和配置
  • 简单的渐变设置示例
  • 命名空间要求

背景样式设置

📄 阅读: references/background-styling.md

阅读时机: 配置渐变、设置颜色、自定义背景外观时

涵盖主题:

  • BackgroundColor 属性和 BrushInfo 类
  • 画刷样式(Solid、Pattern、Gradient、None)
  • 渐变样式(ForwardDiagonal、BackwardDiagonal、Horizontal、Vertical、PathRectangle、PathEllipse)
  • BackColor 和 ForeColor 属性
  • 图案背景的 PatternStyle 选项
  • 用于多色渐变的 GradientColors 数组
  • 创建自定义颜色过渡
  • 完整的样式设置示例

边框配置

📄 阅读: references/border-configuration.md

阅读时机: 添加边框、自定义边框样式、控制边框外观时

涵盖主题:

  • BorderSides 属性(Left、Top、Right、Bottom、Middle、All)
  • BorderStyle 选项(Raised、Sunken、Flat、Etched、Bump 等)
  • 用于设置 2D 边框颜色的 BorderColor
  • Border3DStyle 枚举
  • FixedSingle 边框模式
  • 选择性边框
  • 3D 边框效果
  • 完整的边框示例

前景和文本设置

📄 阅读: references/foreground-text-settings.md

阅读时机: 配置文本外观、设置字体属性、管理禁用状态时

涵盖主题:

  • 用于标签内容的 Text 属性
  • 用于设置文本颜色的 ForeColor
  • DrawActiveWhenDisabled 属性
  • 从 Label 继承的字体属性
  • 文本对齐选项(继承而来)
  • TextAlign 属性用法
  • 控制禁用状态的外观
  • 文本可见性和样式设置

序列化

📄 阅读: references/serialization.md

阅读时机: 保存/加载渐变设置、持久化视觉状态、实现主题时

涵盖主题:

  • XML 序列化概述
  • 将 BackgroundColor 保存到 XML 文件
  • 从 XML 文件加载 BackgroundColor
  • XmlSerializer 类的用法
  • FileStream 和 XmlTextWriter 的实现
  • 跨会话持久化渐变状态
  • 主题保存/加载模式
  • 完整的序列化示例

快速入门

基本渐变标签设置
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.Drawing;

// Create and configure GradientLabel
GradientLabel gradientLabel = new GradientLabel();
gradientLabel.Size = new Size(200, 60);
gradientLabel.Location = new Point(20, 20);

// Set gradient background (horizontal red to blue)
gradientLabel.BackgroundColor = new BrushInfo(
    GradientStyle.Horizontal,
    Color.Red,
    Color.MediumBlue
);

// Set text properties
gradientLabel.Text = "Welcome";
gradientLabel.ForeColor = Color.White;
gradientLabel.Font = new Font("Arial", 14, FontStyle.Bold);

// Add to form
this.Controls.Add(gradientLabel);
添加边框样式
// Add 3D border effect
gradientLabel.BorderStyle = Border3DStyle.Raised;
gradientLabel.BorderSides = Border3DSide.All;

常见模式

模式 1:垂直渐变分区标题
// Create attractive section header
GradientLabel header = new GradientLabel
{
    Size = new Size(300, 50),
    Location = new Point(10, 10),
    Text = "User Information",
    Font = new Font("Segoe UI", 16, FontStyle.Bold),
    TextAlign = ContentAlignment.MiddleCenter,
    ForeColor = Color.White
};

// Vertical gradient from dark to light blue
header.BackgroundColor = new BrushInfo(
    GradientStyle.Vertical,
    Color.DarkBlue,
    Color.LightSkyBlue
);

// Raised 3D border
header.BorderStyle = Border3DStyle.Raised;
模式 2:多色渐变标签
// Create label with multiple gradient colors
GradientLabel colorfulLabel = new GradientLabel
{
    Size = new Size(250, 80),
    Text = "Special Offer!",
    Font = new Font("Arial", 18, FontStyle.Bold),
    ForeColor = Color.White,
    TextAlign = ContentAlignment.MiddleCenter
};

// Path rectangle gradient with 5 colors
colorfulLabel.BackgroundColor = new BrushInfo(
    GradientStyle.PathRectangle,
    new Color[]
    {
        Color.LavenderBlush,
        Color.LemonChiffon,
        Color.DarkKhaki,
        Color.SandyBrown,
        Color.LightSeaGreen
    }
);
模式 3:带样式的状态标签
// Create status indicator label
GradientLabel statusLabel = new GradientLabel
{
    Size = new Size(150, 30),
    Text = "Active",
    TextAlign = ContentAlignment.MiddleCenter,
    ForeColor = Color.DarkGreen,
    Font = new Font("Arial", 10, FontStyle.Bold)
};

// Horizontal gradient (light green)
statusLabel.BackgroundColor = new BrushInfo(
    GradientStyle.Horizontal,
    Color.LightGreen,
    Color.PaleGreen
);

// Flat border with custom color
statusLabel.BorderStyle = Border3DStyle.Flat;
statusLabel.BorderSides = Border3DSide.All;
statusLabel.BorderColor = Color.DarkGreen;

关键属性

背景属性
  • BackgroundColor:使用 BrushInfo 类获取/设置背景颜色和样式
  • BackgroundColor.Style:画刷样式(Solid、Pattern、Gradient、None)
  • BackgroundColor.GradientStyle:渐变方向(Horizontal、Vertical、ForwardDiagonal、BackwardDiagonal、PathRectangle、PathEllipse)
  • BackgroundColor.BackColor:渐变的起始颜色
  • BackgroundColor.ForeColor:渐变的结束颜色
  • BackgroundColor.PatternStyle:使用 Pattern 模式时的图案样式
  • BackgroundColor.GradientColors:多色渐变的颜色数组
边框属性
  • BorderSides:显示边框的边(Left、Top、Right、Bottom、Middle、All)
  • BorderStyle:3D 边框样式(Raised、RaisedOuter、RaisedInner、Sunken、SunkenOuter、SunkenInner、Etched、Bump、Adjust、Flat)
  • BorderColor:2D 边框的颜色(当 BorderStyle 为 FixedSingle 时生效)
文本属性(继承自 Label)
  • Text:标签文本内容
  • Font:显示文本所用的字体
  • ForeColor:文本颜色
  • TextAlign:文本对齐方式(ContentAlignment 枚举)
  • DrawActiveWhenDisabled:控件禁用时是否正常绘制文本
标准标签属性
  • 可使用 System.Windows.Forms.Label 的所有属性
  • Size、Location、Enabled、Visible 等

常见用例

窗体分区标题

为窗体中相关控件的分组创建醒目的分区标题。

仪表板面板

在仪表板应用程序中构建美观的信息面板和状态显示。

品牌元素

通过自定义配色方案和渐变效果实现公司品牌设计。

状态指示器

设计醒目的状态标签,并使用渐变颜色区分状态(成功、警告、错误)。

装饰性文本

为重要文本、公告或宣传消息增添视觉吸引力。

基于主题的标签

创建可通过序列化保存和加载的主题标签。

注意事项

  • GradientLabel 继承自 System.Windows.Forms.Label,因此可使用所有标准 Label 功能
  • BrushInfo 类提供渐变和样式功能
  • BackgroundColor 属性是自定义的关键
  • 只有当 BorderStyle 设置为 Border3DStyle.Flat 时,BorderColor 才会生效
  • 渐变颜色数组的首项与 BackColor 相同,末项与 ForeColor 相同
  • XML 序列化可以跨应用程序会话持久化渐变设置
  • 性能针对常见用法进行了优化;控件数量较多时,应避免渐变过于复杂

评论

支持 Markdown