简介

KryptonGroupBox 是增强型分组框控件,替代标准 System.Windows.Forms.GroupBox。它保留经典的「边框 + 左上角标题文字」样式,同时跟随 Krypton 主题渲染,标题文字与边框颜色可逐状态自定义,适合在设置面板、表单分区中对相关控件进行视觉分组。

KryptonGroupBox 示例截图
KryptonGroupBox 对表单控件进行分组

常用属性

属性类型说明
Values.Headingstring分组框标题文字
Values.Descriptionstring标题旁的补充描述文字
Values.ImageImage标题左侧图标
StateCommon.Border.Color1Color边框颜色
StateCommon.Border.Widthint边框宽度(-1 表示使用主题默认值)
StateCommon.Border.Roundingint边框圆角半径
StateCommon.Content.ShortText.Color1Color标题文字颜色
StateCommon.Content.ShortText.FontFont标题文字字体
StateCommon.Back.Color1Color分组框内部背景色
PanelKryptonGroup内部内容面板(子控件实际添加到 Panel 中)
Controls集合子控件集合(通过 Panel 承载)

快速上手

基本用法

using Krypton.Toolkit;

// 创建分组框
var grpUser = new KryptonGroupBox();
grpUser.Values.Heading = "用户信息";
grpUser.Location = new Point(16, 16);
grpUser.Size = new Size(320, 160);

// 向分组框内添加控件
var lblName = new KryptonLabel();
lblName.Values.Text = "姓名:";
lblName.Location = new Point(12, 28);
grpUser.Controls.Add(lblName);

var txtName = new KryptonTextBox();
txtName.Location = new Point(70, 25);
grpUser.Controls.Add(txtName);

this.Controls.Add(grpUser);

带图标与描述的标题

grpUser.Values.Image = Properties.Resources.icon_user;
grpUser.Values.Description = "(必填)";

进阶用法

自定义标题与边框外观

// 加粗标题、主题绿色
grpUser.StateCommon.Content.ShortText.Font =
    new Font("微软雅黑", 9.5f, FontStyle.Bold);
grpUser.StateCommon.Content.ShortText.Color1 = Color.FromArgb(15, 118, 110);

// 圆角边框
grpUser.StateCommon.Border.Rounding = 6;
grpUser.StateCommon.Border.Color1 = Color.FromArgb(153, 246, 228);
grpUser.StateCommon.Border.Width = 1;

禁用整组控件

// Enabled 为 false 时,分组框及其内部所有子控件一起变灰
grpUser.Enabled = false;

// 恢复
grpUser.Enabled = true;
提示:与标准 GroupBox 不同,KryptonGroupBox 的子控件实际挂载在内部 Panel 属性指向的 KryptonGroup 面板上;直接对 Controls 添加即可,无需手动操作 Panel。

对应示例项目

📁 Source/Krypton Toolkit Examples/KryptonGroupBox Examples/

包含:标题图标/描述演示、边框圆角与配色自定义。

相关控件