Configuring GridLayout in Windows Forms LayoutManagers
The configuration settings for
GridLayout have been given in this section.
Rows and columns
GridLayout simply divides the available space into a number of rows and columns based on the number of child controls. The number of rows and columns can be specified using the following properties.
|Rows||Specifies the number of rows in the grid.|
|Columns||Specifies the number of columns in the grid.|
Rows property usually dictates the number of columns (overriding the columns property setting) based on the number of child controls unless the Rows property is set to ‘Null’ or less, so the
Columns property will dictate the number of rows.
The following code snippet demonstrates how to arrange the child controls in one column and two rows.
this.gridLayout1.Rows = 2; this.gridLayout1.Columns = 1;
Me.gridLayout1.Rows = 2 Me.gridLayout1.Columns = 1
HGap and VGap
The horizontal and vertical gaps between the child controls can be set using the following properties.
|HGap||Specifies the horizontal spacing between the layout border and the components.|
|VGap||Specifies the vertical spacing between the layout border and the components.|
Configuring child controls
The following settings can be used to configure the child controls of the GridLayout manager.
To prevent a child control from being laid out using the GridLayout manager, use the following property.
|ParticipateInLayout||Specifies whether the child control should participate in the GridLayout. The default value is set to `true`.|
The methods associated with the above properties are given in the following table.
|GetParticipateInLayout||Indicates whether the component is in the layout list.|
|SetParticipateInLayout||Adds or removes the specified control from the layout list.|
The following code is used to add or remove the control from the GridLayout list programmatically.
Rearranging the controls laid out by GridLayout
The child controls of the GridLayout can be rearranged by dragging and dropping them at design time.