Class FlowLayout
Represents the LayoutManager that does a left to right or top to bottom layout.
Implements
Inherited Members
Namespace: Syncfusion.Windows.Forms.Tools
Assembly: Syncfusion.Shared.Base.dll
Syntax
public class FlowLayout : LayoutManager, IExtenderProvider, ILayoutManager, ISupportInitialize
Remarks
Arranges components horizontally (left to right) or vertically (top to bottom) (As specified in the LayoutMode property). When there is no more space in a line, it moves the components to the next line.
By default, each line is centered. You can change this justification using the Alignment property.
You can also set FlowLayoutConstraints on each component for more control over the component's alignment and spacing within a row / column.
You can control the component spacing, in pixels, through the HGap and VGap properties.
When the FlowLayout 's System.Windows.Forms.ContainerControl changes, it automatically assigns default FlowLayoutConstraints to the children, for convenience sake, so that you don't have to call SetConstraints(Control, FlowLayoutConstraints) for each child component.
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 FlowLayout manager with a container control:
// Binding a control to the FlowLayout manager programmatically:
this.flowLayout1 = new FlowLayout();
// Set the container control; all the child controls of this container control are
// automatically registered as children with the manager:
this.flowLayout1.ContainerControl = this.panel1;
// Set some properties on the FlowLayout manager:
this.flowLayout1.HGap = 20;
this.flowLayout1.Alignment = FlowAlignment.Near;
// You can prevent one or more child controls from being laid out, like this (the first argument for FlowLayoutConstraints should be False).
// This will have the same effect as calling RemoveLayoutComponent:
this.flowLayout1.SetConstraints(this.label10, new FlowLayoutConstraints(false, HorzFlowAlign.Left, VertFlowAlign.Center, false, false, false));
// You can prevent automatic layout during the layout event.
// If you decide to do so, make sure to call flowLayout.LayoutContainer manually:
// this.flowLayout1.AutoLayout = false;
Also take a look at the project in Tools/Samples/Quick Start/LayoutManager for an example.
Constructors
FlowLayout()
Overloaded. Creates a new instance of the FlowLayout component and sets its defaults.
Declaration
public FlowLayout()
FlowLayout(IContainer)
Creates a new instance of the FlowLayout class and adds itself to the specified container.
Declaration
public FlowLayout(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 container control.
FlowLayout(Control)
Creates a new instance of the FlowLayout component and sets its System.Windows.Forms.ContainerControl.
Declaration
public FlowLayout(Control container)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | container | The logical System.Windows.Forms.ContainerControl parent into which to add itself. |
FlowLayout(Control, FlowLayoutMode, FlowAlignment)
Declaration
public FlowLayout(Control container, FlowLayoutMode layoutMode, FlowAlignment align)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | container | |
FlowLayoutMode | layoutMode | |
FlowAlignment | align |
FlowLayout(Control, FlowLayoutMode, FlowAlignment, Int32, Int32)
Declaration
public FlowLayout(Control container, FlowLayoutMode layoutMode, FlowAlignment align, int hGap, int vGap)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | container | |
FlowLayoutMode | layoutMode | |
FlowAlignment | align | |
System.Int32 | hGap | |
System.Int32 | vGap |
Fields
noFillSizes
Declaration
protected Hashtable noFillSizes
Field Value
Type |
---|
System.Collections.Hashtable |
Properties
Alignment
Gets or sets the alignment of layout components in the direction of flow.
Declaration
public FlowAlignment Alignment { get; set; }
Property Value
Type | Description |
---|---|
FlowAlignment | A FlowAlignment value specifying the justification. Default is FlowAlignment.Center. |
Remarks
FlowAlignment.Near will be either left justified or top justified based on whether the layout mode is vertical or horizontal. And similarly, FlowAlignment.Far will be either right justified or bottom justified. FlowAlignment.ChildConstraints will make the manager refer to the child's constraints.
AutoHeight
Indicates whether the container control should automatically grow in height when there is not enough space when in horizontal alignment mode.
Declaration
public bool AutoHeight { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True to automatically increase the height; False otherwise. |
Remarks
This applies only in horizontal alignment mode.
HGap
Gets or sets the horizontal spacing between the components.
Declaration
public int HGap { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The horizontal space in pixels. |
LayoutMode
Gets or sets the layout mode.
Declaration
public FlowLayoutMode LayoutMode { get; set; }
Property Value
Type | Description |
---|---|
FlowLayoutMode | The current FlowLayoutMode. Default is FlowLayoutMode.Horizontal. |
ReverseRows
Indicates whether to lay out rows in the opposite direction (right to left or bottom to top).
Declaration
public bool ReverseRows { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | False for regular layout; True for reverse layout. Default is False. |
VGap
Gets or 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
GetConstraints(Control)
Returns the constraints associated with the specified control.
Declaration
public FlowLayoutConstraints GetConstraints(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control | The control with constraints to retrieve. |
Returns
Type | Description |
---|---|
FlowLayoutConstraints | A clone of the stored constraints object. |
Remarks
The returned value is a clone which can be used independently by itself. The changes made to the returned instance will not have any effect on the stored constraints. Use GetConstraintsRef(Control) to get hold of the actual constraints object that is used by the manager.
GetConstraintsRef(Control)
Returns a reference to the constraints associated with the specified control.
Declaration
public FlowLayoutConstraints GetConstraintsRef(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control | The control with constraints to retrieve. |
Returns
Type | Description |
---|---|
FlowLayoutConstraints | A reference to the actual constraints object. |
Remarks
This is the actual object where the manager stores the constraints for the control. Hence, making changes to the returned object will affect the layout logic.
GetParticipateInLayout(Control)
Indicates whether the component is in the layout list.
Declaration
[Obsolete("This method will be removed in a future version. Use the GetConstraintsRef method instead. Please check the class reference for more information.")]
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. |
Remarks
This method will be removed in a future version. Use the GetConstraintsRef(Control) method to get hold of the FlowLayoutConstraints associated with this control and then check its Active property instead.
GetStaticMinimumSize(Control)
Declaration
protected override Size GetStaticMinimumSize(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control |
Returns
Type |
---|
System.Drawing.Size |
Overrides
GetStaticPreferredSize(Control)
Declaration
protected override Size GetStaticPreferredSize(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
LayoutContainerHorizontal()
Arrange the layout components horizontally in the layout container.
Declaration
public virtual void LayoutContainerHorizontal()
LayoutContainerVertical()
Arranged the layout components vertically in the layout container.
Declaration
public virtual void LayoutContainerVertical()
MinimumLayoutSize()
Overridden. See MinimumLayoutSize().
Declaration
public override Size MinimumLayoutSize()
Returns
Type |
---|
System.Drawing.Size |
Overrides
MoveComponentsHorizontal(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Hashtable, Hashtable)
Declaration
protected virtual void MoveComponentsHorizontal(int x, int y, int maxWidth, int deltaWidth, int height, int rowStart, int rowEnd, Hashtable prefSizes, Hashtable deltaWidths)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | |
System.Int32 | y | |
System.Int32 | maxWidth | |
System.Int32 | deltaWidth | |
System.Int32 | height | |
System.Int32 | rowStart | |
System.Int32 | rowEnd | |
System.Collections.Hashtable | prefSizes | |
System.Collections.Hashtable | deltaWidths |
MoveComponentsVertical(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Hashtable, Hashtable)
Declaration
protected virtual void MoveComponentsVertical(int x, int y, int width, int deltaHeight, int maxHeight, int rowStart, int rowEnd, Hashtable prefSizes, Hashtable deltaHeights)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | |
System.Int32 | y | |
System.Int32 | width | |
System.Int32 | deltaHeight | |
System.Int32 | maxHeight | |
System.Int32 | rowStart | |
System.Int32 | rowEnd | |
System.Collections.Hashtable | prefSizes | |
System.Collections.Hashtable | deltaHeights |
OnContainerControlChanged(EventArgs)
Overridden. See OnContainerControlChanged(EventArgs).
Declaration
protected override void OnContainerControlChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | An EventArgs that contains the event data. |
Overrides
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
OnGapChanged(ValueChangedEventHandler, ValueChangedEventArgs)
Declaration
protected void OnGapChanged(ValueChangedEventHandler gapChangedHandler, ValueChangedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
ValueChangedEventHandler | gapChangedHandler | |
ValueChangedEventArgs | args |
PreferredLayoutSize()
Overridden. See PreferredLayoutSize().
Declaration
public override Size PreferredLayoutSize()
Returns
Type | Description |
---|---|
System.Drawing.Size | Returns the size with the preferred height (when laying out Horizontal) or size with the preferred width (when laying out Vertical). |
Overrides
RemoveLayoutComponent(Control)
Removes a child component from the layout list.
Declaration
public override void RemoveLayoutComponent(Control childControl)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | childControl | The control to be removed. |
Overrides
Remarks
You can also pass a LayoutItemBase derived class as the first argument because it has an implicit type-conversion operator that will provide its corresponding control object (a place-holder control that allows the LayoutItemBase to participate in the layout framework seemlessly). In VB, use the LayoutItemBase.ToControl method.
ResetConstraints(Control)
Declaration
protected void ResetConstraints(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control |
ResetLayoutInfo()
Overridden. See ResetLayoutInfo().
Declaration
protected override void ResetLayoutInfo()
Overrides
ResetMinimumSize(Control)
Overridden. See ResetMinimumSize(Control).
Declaration
public override void ResetMinimumSize(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control | The Control which MinimumSize to be reset. |
Overrides
ResetPreferredSize(Control)
Overridden. See ResetPreferredSize(Control).
Declaration
public override void ResetPreferredSize(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control | The control which PreferredSize to be reset. |
Overrides
SetConstraints(Control, FlowLayoutConstraints)
Specifies the constraints associated with the specified control.
Declaration
public void SetConstraints(Control control, FlowLayoutConstraints value)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control | The control for which to set the constraints. |
FlowLayoutConstraints | value | The constraints of the control. NULL to remove the control from the layout list. |
Remarks
Passing a NULL value will actually remove the component from the layout list.
SetParticipateInLayout(Control, Boolean)
Adds or removes the specified control from the layout list.
Declaration
[Obsolete("This method will be removed in a future version. Use the SetConstraints method instead. Please check the class reference for more information.")]
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. |
Remarks
This method will be removed in a future version. Instead, use the SetConstraints(Control, FlowLayoutConstraints) method passing in a FlowLayoutConstraints instance with its Active property set to the appropriate value.
SetPreferredSize(Control, Size)
Overridden. See SetPreferredSize(Control, Size).
Declaration
public override void SetPreferredSize(Control control, Size value)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control | The control to associate the preferred size with. |
System.Drawing.Size | value | The preferred size of the control. |
Overrides
ShouldSerializeConstraints(Control)
Declaration
protected bool ShouldSerializeConstraints(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control |
Returns
Type |
---|
System.Boolean |
ShouldSerializeMinimumSize(Control)
Indicates whether to serialize the MinimumSize property.
Declaration
public override bool ShouldSerializeMinimumSize(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control |
Returns
Type |
---|
System.Boolean |
Overrides
ShouldSerializePreferredSize(Control)
Indicates whether to serialize the PreferredSize property.
Declaration
public override bool ShouldSerializePreferredSize(Control control)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Control | control |
Returns
Type |
---|
System.Boolean |
Overrides
Events
HGapChanged
Occurs when HGap property is changed.
Declaration
public event ValueChangedEventHandler HGapChanged
Event Type
Type |
---|
ValueChangedEventHandler |
VGapChanged
Occurs when VGap property is changed.
Declaration
public event ValueChangedEventHandler VGapChanged
Event Type
Type |
---|
ValueChangedEventHandler |