Class GridLayout
Represents the LayoutManager that lays out the child components as a grid consisting of rows and columns.
Implements
Inherited Members
Namespace: Syncfusion.Windows.Forms.Tools
Assembly: Syncfusion.Shared.Base.dll
Syntax
public class GridLayout : LayoutManager, IExtenderProvider, ILayoutManager, ISupportInitialize
Remarks
The LayoutManager divides the layout space into rows and columns based on the Rows and Columns properties and assigns each similar sized cell to a child component.
You can control the component spacing, in pixels, through the HGap and VGap properties.
You can remove or add child controls through the SetParticipateInLayout method. When the GridLayout's ContainerControl changes, it automatically includes all of its children in the layout component list, for convenience sake, so that you don't have to call SetParticipateInLayout for each child component.
The PreferredSize and MinimimumSize settings for the children are ignored by the GridLayout during layout, however the PreferredLayoutSize() and MinimumLayoutSize() methods do refer to the above settings to determine the sizes.
Take a look at the LayoutManager class documentation for more information on LayoutManager in general.
Examples
The following example shows you how to initialize a GridLayout manager with a container control:
// Binding a Control to the GridLayout manager programmatically:
this.gridLayout1 = new Syncfusion.Windows.Forms.Tools.GridLayout();
// Set the container control; all the child controls of this container control are
// automatically registered as children with the manager:
this.gridLayout1.ContainerControl = this.innerPanel;
// Set some properties on the GridLayout manager:
this.gridLayout1.Columns = 4;
this.gridLayout1.Rows = 5;
this.gridLayout1.HGap = 4;
this.gridLayout1.VGap = 4;
// You can ignore one or more child Control from being laid out, like this.
// This will have the same effect as calling RemoveLayoutComponent:
//this.gridLayout1.SetParticipateInLayout(this.button1, false);
// You can prevent automatic layout during the layout event:
// If you decide to do so, make sure to call gridLayout1.LayoutContainer manually:
// this.gridLayout1.AutoLayout = false;
Also take a look at the project in Tools/Samples/Quick Start/LayoutManager for an example.
Constructors
GridLayout()
Overloaded. Creates an instance of the GridLayout class and sets its defaults.
Declaration
public GridLayout()
GridLayout(IContainer)
Creates a new instance of the GridLayout class and adds itself to the specified container.
Declaration
public GridLayout(IContainer container)
Parameters
Type | Name | Description |
---|---|---|
System.ComponentModel.IContainer | container | The logical System.Windows.Forms.ContainerControl parent into which to add itself. |
Remarks
This constructor is used by the design-time to add a component to the form's IContainer field so that it gets Disposed when the form gets Disposed.
Note that this is not the same as the LayoutManager's ContainerControl.
GridLayout(Control)
Creates an instance of the GridLayout class and sets its ContainerControl.
Declaration
public GridLayout(Control container)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | container | The logical System.Windows.Forms.ContainerControl parent into which to add itself. |
GridLayout(Control, Int32, Int32)
Creates an instance of the GridLayout class and sets its ContainerControl, rows and columns.
Declaration
public GridLayout(Control container, int rows, int columns)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | container | The logical System.Windows.Forms.ContainerControl parent into which to add itself. |
System.Int32 | rows | Number of rows to be displayed in the GridLayout |
System.Int32 | columns | Number of columns to be displayed in the GridLayout |
GridLayout(Control, Int32, Int32, Int32, Int32)
Creates an instance of the GridLayout class and sets its ContainerControl, rows, columns, horizontal gap and vertical gap.
Declaration
public GridLayout(Control container, int rows, int columns, int hGap, int vGap)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | container | The logical System.Windows.Forms.ContainerControl parent into which to add itself. |
System.Int32 | rows | Number of rows to be displayed in the GridLayout. |
System.Int32 | columns | Number of columns to be displayed in the GridLayout. |
System.Int32 | hGap | The horizontal space between the child controls. |
System.Int32 | vGap | The vertical space between the child controls. |
Properties
Columns
Gets / sets the number of columns to be displayed in the LayoutManager.
Declaration
public int Columns { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The number of columns. Default is 1. |
Remarks
At least one Row or Column property should be greater than zero. If they are both set to zero, then the Row property will be changed to 1.
If you try to set a negative value, this will instead be set to zero.
HGap
Gets / sets the horizontal spacing between the layout border and the components.
Declaration
public int HGap { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The horizontal space in pixels. |
Rows
Gets / sets the number of rows to be displayed in the LayoutManager.
Declaration
public int Rows { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The number of rows. Default is 1. |
Remarks
At least one Row or Column property should be greater than zero. If they are both set to zero, then the Rows property will be changed to 1.
If you try to set a negative value, this will instead be set to zero.
VGap
Gets / sets the vertical spacing between the layout border and the components.
Declaration
public int VGap { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The vertical space in pixels. |
Methods
GetMinimumSize(Control)
Retrieves the minimum size associated with the specified control. GetMinimumSize(Control)
Declaration
public override Size GetMinimumSize(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control |
Returns
Type |
---|
System.Drawing.Size |
Overrides
GetParticipateInLayout(Control)
Indicates whether the component is in the layout list.
Declaration
public bool GetParticipateInLayout(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control | The control whose participation needs to be verified. |
Returns
Type | Description |
---|---|
System.Boolean | True if it is in the layout list; False otherwise. |
GetPreferredSize(Control)
Retrieves the preferred size associated with the specified control. GetPreferredSize(Control)
Declaration
public override Size GetPreferredSize(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control |
Returns
Type |
---|
System.Drawing.Size |
Overrides
LayoutContainer()
Overridden. See LayoutContainer().
Declaration
public override void LayoutContainer()
Overrides
MinimumLayoutSize()
Overridden. See MinimumLayoutSize().
Declaration
public override Size MinimumLayoutSize()
Returns
Type |
---|
System.Drawing.Size |
Overrides
OnContainerControlChanged(EventArgs)
Overridden. See OnContainerControlChanged(EventArgs).
Declaration
protected override void OnContainerControlChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e |
Overrides
OnControlAdded(Object, ControlEventArgs)
Overridden. See OnControlAdded(Object, ControlEventArgs).
Declaration
protected override void OnControlAdded(object sender, ControlEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | |
System.Windows.Forms.ControlEventArgs | e |
Overrides
PreferredLayoutSize()
Overridden. See PreferredLayoutSize().
Declaration
public override Size PreferredLayoutSize()
Returns
Type | Description |
---|---|
System.Drawing.Size | Returns the preferred layout size. |
Overrides
ResetLayoutInfo()
Declaration
protected override void ResetLayoutInfo()
Overrides
SetParticipateInLayout(Control, Boolean)
Adds or removes the specified control from the layout list.
Declaration
public void SetParticipateInLayout(Control control, bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control | The control to be added or removed. |
System.Boolean | value | True means the control will be added; False will remove it. |