Loading...
Loading...
Implement grid-based layout management in Windows Forms using GridLayout component. Arrange child controls in rows and columns with configurable spacing and control participation.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-grid-layoutusing 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);| Property | Type | Purpose |
|---|---|---|
| Rows | int | Specifies number of rows in the grid (dictates columns if set) |
| Columns | int | Specifies number of columns (used when Rows is null or negative) |
| HGap | int | Horizontal spacing between controls and layout border |
| VGap | int | Vertical spacing between controls and layout border |
| ContainerControl | Control | The form or container that holds the layout manager |
gridLayout1.Rows = null; // Let rows auto-calculate
gridLayout1.Columns = 1;gridLayout1.Rows = 3;
gridLayout1.Columns = 3;
gridLayout1.HGap = 5;
gridLayout1.VGap = 5;// Hide a control from layout without removing it
gridLayout1.SetParticipateInLayout(controlToHide, false);