关于 syncfusion-winforms-grid-layout
为 Syncfusion Windows Forms GridLayout 提供实施指南,面向需要用行列网格排列控件的 Windows Forms 开发者。内容涵盖布局配置、间距及控件参与管理。
主要功能
- 01按行列自动排列控件
- 02配置行数与列数
- 03设置水平和垂直间距
- 04动态控制控件是否参与布局
- 05支持代码或设计器配置
适用场景
- 01构建垂直排列的单列布局
- 02创建间距一致的网格界面
- 03隐藏控件并调整布局而不移除控件
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ syncfusion/ winforms-ui-components-skills --skill syncfusion-winforms-grid-layout安装后在 Claude Code 中输入/syncfusion-winforms-grid-layout确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/getting-started.mdmanaging-child-controls.mdrows-and-columns-configuration.mdspacing-and-gaps.md详细介绍
在 Windows Forms 中实现 GridLayout
GridLayout 是一种布局管理器,可在包含行和列的网格结构中自动排列子控件。需要以结构化的网格形式组织多个控件并精确控制间距时,请使用此技能。
何时使用此技能
- 在基于网格的布局中排列子控件
- 创建统一的行列结构
- 控制控件之间的水平和垂直间距
- 动态包含或排除控件
- 以编程方式或通过设计器排列控件
组件概览
GridLayout 提供:
- 网格结构:自动按行和列排列
- 间距控制:配置水平(HGap)和垂直(VGap)间距
- 控件参与管理:将控件包含在布局管理中或排除在外
- 动态配置:可通过编程方式设置行和列
文档与导航指南
入门
📄 阅读: references/getting-started.md
- 程序集部署与 NuGet 设置
- 通过设计器或代码创建 GridLayout
- 向布局中添加子控件
- 基本实现模式
行列配置
📄 阅读: references/rows-and-columns-configuration.md
- 设置行数和列数
- 了解 Rows 属性的优先级
- 根据子控件数量自动调整大小的行为
- 网格划分策略
间距
📄 阅读: references/spacing-and-gaps.md
- 配置水平间距(HGap)
- 配置垂直间距(VGap)
- 间距计算及其影响
- 常见间距模式
管理子控件
📄 阅读: references/managing-child-controls.md
- ParticipateInLayout 属性概览
- 在布局中添加或移除控件
- 检查控件是否参与布局
- 在设计时重新排列控件
快速入门示例
using Syncfusion.Windows.Forms.Tools;
// Create GridLayout instance
GridLayout gridLayout1 = new GridLayout();
gridLayout1.ContainerControl = this;
// Configure grid structure
gridLayout1.Rows = 2;
gridLayout1.Columns = 2;
// Set spacing
gridLayout1.HGap = 10;
gridLayout1.VGap = 10;
// Add child controls
ButtonAdv button1 = new ButtonAdv() { Text = "Button 1" };
ButtonAdv button2 = new ButtonAdv() { Text = "Button 2" };
this.Controls.Add(button1);
this.Controls.Add(button2);
// Include controls in layout
gridLayout1.SetParticipateInLayout(button1, true);
gridLayout1.SetParticipateInLayout(button2, true);
关键配置属性
| 属性 | 类型 | 用途 |
|---|---|---|
| Rows | int | 指定网格的行数(设置后决定列数) |
| Columns | int | 指定列数(Rows 为 null 或负数时使用) |
| HGap | int | 控件与布局边框之间的水平间距 |
| VGap | int | 控件与布局边框之间的垂直间距 |
| ContainerControl | Control | 容纳布局管理器的窗体或容器 |
常见模式
模式 1:单列布局
gridLayout1.Rows = null; // Let rows auto-calculate
gridLayout1.Columns = 1;
适用于垂直堆叠控件。
模式 2:间距均匀的网格
gridLayout1.Rows = 3;
gridLayout1.Columns = 3;
gridLayout1.HGap = 5;
gridLayout1.VGap = 5;
创建间距为 5 像素的 3x3 网格。
模式 3:有条件地显示控件
// Hide a control from layout without removing it
gridLayout1.SetParticipateInLayout(controlToHide, false);
无需移除控件即可动态调整布局。
评论
支持 Markdown