mcpField
S
syncfusion-winforms-radio-button

syncfusion-winforms-radio-button

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

关于 syncfusion-winforms-radio-button

此技能介绍 Syncfusion WinForms RadioButtonAdv 增强型单选按钮,面向需要灵活外观配置的应用开发者,涵盖 Office 和 Metro 主题、文字效果、渐变、图像及行为设置。

主要功能

  1. 01Office、Metro 和默认主题
  2. 02可配置颜色与偏移的文字阴影
  3. 03渐变背景和边框样式
  4. 04各按钮状态的自定义图像
  5. 05灵活的文字与按钮对齐
  6. 06关联整数或字符串值

适用场景

  1. 01设置对话框中的主题化选项
  2. 02选择向导步骤
  3. 03设置多选问卷的选项样式
  4. 04保存选定的用户偏好

安装

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

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

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

包含的文件

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

references/
appearance-customization.md
behavior-settings.md
events.md
getting-started.md
text-settings.md
themes-and-styles.md

详细介绍

在 Syncfusion WinForms 中实现 RadioButtonAdv

本技能将指导你实现 Syncfusion WinForms RadioButtonAdv 控件——一种增强型单选按钮,支持 Office 主题、渐变背景、文本阴影效果、自定义图像和专业外观等高级样式选项。

何时使用此技能

当用户需要以下功能时,请使用此技能:

  • 实现具有现代样式的增强型单选按钮,超越标准 RadioButton 的外观
  • 应用 Office 主题(Office2007、Office2016 Colorful/White/Black/DarkGray)
  • 使用 Metro 风格的单选按钮设计现代 UI
  • 添加具有自定义颜色和偏移量的文本阴影效果
  • 为单选按钮创建渐变背景
  • 为不同的单选按钮状态显示自定义图像
  • 为单选按钮应用 2D 或 3D 边框样式
  • 为自定义布局配置文本和按钮对齐方式
  • 将整数或字符串值与单选按钮状态关联
  • 构建具有一致 Office 风格主题的专业窗体
  • 使用外观增强的替代控件替换标准 RadioButton

当单选按钮控件的视觉外观和主题很重要时,RadioButtonAdv 是理想之选。

组件概览

RadioButtonAdv 是一种高级单选按钮控件,在标准 WinForms RadioButton 的基础上扩展了丰富的样式功能。它提供:

  • 主题支持:Office2007、Office2016、Metro 和 Default 主题
  • 文本效果:可自定义颜色和偏移量的阴影文本
  • 背景:支持自定义颜色的渐变背景
  • 边框:2D 和 3D 边框样式选项
  • 图像:为每种选中状态设置自定义图像
  • 对齐方式:灵活设置文本和按钮的位置
  • 值关联:为每种状态设置整数或字符串值
  • 行为选项:自动高度、焦点矩形和单击事件

与标准 RadioButton 的主要区别: RadioButtonAdv 在保留标准单选按钮功能的同时,增加了视觉样式和主题功能。

文档与导航指南

入门与基本设置

📄 阅读: references/getting-started.md

当用户需要以下内容时,请阅读此参考资料:

  • 程序集依赖项和 NuGet 包安装
  • 通过设计器或代码创建 RadioButtonAdv
  • 基本属性(Text、Font、ForeColor、BackColor)
  • 将 RadioButtonAdv 添加到窗体
  • 了解控件层次结构
  • 完整的最小可运行示例
主题与视觉样式

📄 阅读: references/themes-and-styles.md

当用户需要以下内容时,请阅读此参考资料:

  • 使用 ThemesEnabled 属性启用主题
  • 设置 Style 属性(Default、Office2007、Metro、Office2016 各变体)
  • Office2007ColorScheme(Managed、Blue、Silver、Black)
  • 为 Office2007 主题设置自定义管理颜色
  • 完整的主题示例
  • 专业的 Office 风格外观
文本设置与效果

📄 阅读: references/text-settings.md

当用户需要以下内容时,请阅读此参考资料:

  • 用于阴影效果的 TextShadow 属性
  • 自定义 ShadowColor
  • 设置 ShadowOffset 位置
  • 使用 WrapText 处理长文本
  • 文本效果示例
  • 文本样式最佳实践
外观自定义

📄 阅读: references/appearance-customization.md

当用户需要以下内容时,请阅读此参考资料:

  • 使用自定义颜色设置渐变背景
  • 边框样式(2D 和 3D 选项)
  • 文本和按钮的对齐设置
  • 为不同状态设置自定义图像
  • 完整的外观自定义
  • 高级样式模式
行为设置

📄 阅读: references/behavior-settings.md

当用户需要以下内容时,请阅读此参考资料:

  • 使用 AutoHeight 自动计算高度
  • 控制 DrawFocusRectangle 的可见性
  • 配置 RaiseEventOnClick 事件行为
  • RadioButtonAdv Settings(整数或字符串值关联)
  • 行为配置选项
事件

📄 阅读: references/events.md

当用户需要了解以下内容时,请阅读此参考文档:

  • 可用的 RadioButtonAdv 事件
  • Click 事件处理
  • CheckedChanged 事件
  • 事件最佳实践
  • 常见事件模式

快速入门示例

以下是创建主题化 RadioButtonAdv 控件的最简示例:

using Syncfusion.Windows.Forms.Tools;
using System;
using System.Drawing;
using System.Windows.Forms;

public class RadioButtonExample : Form
{
    private RadioButtonAdv radioButtonAdv1;
    private RadioButtonAdv radioButtonAdv2;
    private RadioButtonAdv radioButtonAdv3;
    
    public RadioButtonExample()
    {
        // Create first radio button
        radioButtonAdv1 = new RadioButtonAdv();
        radioButtonAdv1.Text = "Option 1";
        radioButtonAdv1.Location = new Point(20, 20);
        radioButtonAdv1.Size = new Size(120, 21);
        radioButtonAdv1.Style = RadioButtonAdvStyle.Office2016Colorful;
        radioButtonAdv1.Checked = true;
        
        // Create second radio button
        radioButtonAdv2 = new RadioButtonAdv();
        radioButtonAdv2.Text = "Option 2";
        radioButtonAdv2.Location = new Point(20, 50);
        radioButtonAdv2.Size = new Size(120, 21);
        radioButtonAdv2.Style = RadioButtonAdvStyle.Office2016Colorful;
        
        // Create third radio button
        radioButtonAdv3 = new RadioButtonAdv();
        radioButtonAdv3.Text = "Option 3";
        radioButtonAdv3.Location = new Point(20, 80);
        radioButtonAdv3.Size = new Size(120, 21);
        radioButtonAdv3.Style = RadioButtonAdvStyle.Office2016Colorful;
        
        // Add to form
        this.Controls.Add(radioButtonAdv1);
        this.Controls.Add(radioButtonAdv2);
        this.Controls.Add(radioButtonAdv3);
        
        this.Text = "RadioButtonAdv Example";
        this.Size = new Size(300, 200);
    }
}

**结果:**三个采用 Office2016 主题、外观现代的单选按钮。

常见模式

主题化单选按钮组

**模式:**创建一组采用一致 Office2016 主题的单选按钮。

// Create GroupBox for radio buttons
GroupBox groupBox = new GroupBox();
groupBox.Text = "Select Option";
groupBox.Location = new Point(10, 10);
groupBox.Size = new Size(200, 120);

// Create themed radio buttons
string[] options = { "Small", "Medium", "Large" };
int yPos = 20;

foreach (string option in options)
{
    RadioButtonAdv radio = new RadioButtonAdv();
    radio.Text = option;
    radio.Location = new Point(10, yPos);
    radio.Style = RadioButtonAdvStyle.Office2016Colorful;
    radio.ThemesEnabled = true;
    groupBox.Controls.Add(radio);
    yPos += 30;
}

this.Controls.Add(groupBox);

**适用场景:**用户需要多个相关选项,并希望主题保持一致。

带文本阴影的单选按钮

**模式:**添加文本阴影效果,增强视觉强调。

RadioButtonAdv shadowRadio = new RadioButtonAdv();
shadowRadio.Text = "Important Option";
shadowRadio.TextShadow = true;
shadowRadio.ShadowColor = Color.Gold;
shadowRadio.ShadowOffset = new Point(2, 2);
shadowRadio.Font = new Font("Segoe UI", 10, FontStyle.Bold);
shadowRadio.Location = new Point(20, 20);

**适用场景:**用户希望突出显示特定的单选按钮选项。

自定义渐变背景

**模式:**创建带渐变背景的单选按钮,呈现现代外观。

RadioButtonAdv gradientRadio = new RadioButtonAdv();
gradientRadio.Text = "Premium Option";
// Gradient properties set via designer or property grid
// GradientStart, GradientEnd, GradientStyle
gradientRadio.Location = new Point(20, 20);

**适用场景:**用户需要自定义品牌风格或样式的单选按钮。

关键属性

主题和样式属性
属性类型描述使用时机
StyleRadioButtonAdvStyleOffice2007、Metro、Office2016 变体应用现代主题
ThemesEnabledbool启用或禁用主题控制主题应用
Office2007ColorSchemeOffice2007ThemeBlue、Silver、Black、Managed使用 Office2007 配色变体
文本属性
属性类型描述使用时机
TextShadowbool启用文本阴影效果为文本增加视觉层次
ShadowColorColor阴影颜色自定义阴影外观
ShadowOffsetPoint阴影位置偏移量控制阴影位置
WrapTextbool启用文本换行处理较长的文本标签
外观属性
属性类型描述使用时机
DrawFocusRectanglebool显示或隐藏焦点矩形控制焦点指示器
AutoHeightbool自动计算高度根据内容大小调整
BackColorColor背景颜色设置自定义背景
ForeColorColor文本颜色设置自定义文本颜色
行为属性
属性类型描述使用时机
RaiseEventOnClickbool触发 OnClick 事件控制点击行为
Checkedbool单选按钮状态设置默认选项

常见使用场景

设置对话框

创建带主题化单选按钮的设置表单:

  • 将相关选项分组(主题、大小、布局)
  • 应用一致的 Office2016 主题
  • 采用与应用程序风格一致的专业外观
向导步骤选择

用于向导导航的单选按钮:

  • 使用 Metro 或 Office2016 样式,呈现现代外观
  • 使用文本阴影突出显示当前步骤
  • 建立清晰的视觉层次
调查问卷表单

使用样式化单选按钮实现多选题:

  • 所有问题采用一致的主题
  • 较长的选项标签支持文本换行
  • 呈现专业的问卷外观
首选项配置

用户首选项选择:

  • 为高级选项设置渐变背景
  • 为每种状态设置自定义图像,作为视觉指示
  • 关联值,便于存储首选项

实施检查清单

实现 RadioButtonAdv 时,请确保:

  • ✅ 引用了必需程序集(Syncfusion.Tools.Windows.dll 等)
  • ✅ 包含命名空间(Syncfusion.Windows.Forms.Tools)
  • ✅ 创建并配置了 RadioButtonAdv 实例
  • ✅ 应用了样式/主题,确保外观一致
  • ✅ 设置了文本属性(Text、Font 和可选的阴影)
  • ✅ 指定了用于布局的位置和大小
  • ✅ 为 CheckedChanged 或 Click 添加了事件处理程序
  • ✅ 正确配置了单选按钮组(每组仅选中一个选项)
  • ✅ 使用 Checked 属性设置了默认选项
  • ✅ 使用不同主题和样式进行了测试

故障排除速查表

问题: 主题未应用

  • 设置 ThemesEnabled = true
  • 确保将 Style 属性设为所需主题
  • 检查自定义 BackColor 是否覆盖了主题

问题: 文本阴影不可见

  • 设置 TextShadow = true
  • 选择对比明显的 ShadowColor
  • 调整 ShadowOffset 以使阴影清晰可见

问题: 单选按钮无法互斥

  • 确保单选按钮位于同一容器中(Form、Panel、GroupBox)
  • 只有位于同一父容器中的单选按钮才会被分为一组

问题: 焦点矩形始终可见

  • 设置 DrawFocusRectangle = false 以隐藏焦点矩形
  • 检查窗体级设置是否覆盖了控件设置

问题: 高度未随文本调整

  • 设置 AutoHeight = true
  • 如果文本较长,请确保已配置 WrapText

总结

RadioButtonAdv 提供了增强的单选按钮功能,包括:

  • 专业主题:Office2007、Office2016、Metro 样式
  • 文本效果:支持自定义颜色和偏移量的阴影
  • 视觉自定义:渐变、边框、图像
  • 灵活样式:对齐方式、外观和行为选项

如果创建专业、现代的 WinForms 应用时需要注重视觉外观和主题,可使用 RadioButtonAdv。

评论

支持 Markdown