70-526 MCTSFlowLayoutPanel controlThe FlowLayoutPanel control is a container control where child controls are added, then dynamically repositioned to flow in a particular direction. The FlowLayoutPanel automatically positions all child controls in the direction indicated by the value of the FlowDirection property. You can leave the WrapContents property set to the default value of True to force the controls to stay within the boundaries of the SplitContainer class by starting a new row or column, depending on the value of the FlowDirection property. Inheritance hierarchy System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.Panel
System.Windows.Forms.FlowLayoutPanel
Useful properties
Useful methodsDocking a FlowLayoutPanel in a FormA FlowLayoutPanel can be docked into the parent container, by selecting the FlowLayoutPanel and clicking on the
Smart Tag icon ![]() To undock the FlowLayoutPanel, click on the Smart Tag icon ![]() Wraping the contents using WrapContentsIf this property is set to true, the layout control wraps the controls once they extend beyond the boundary specified by the FlowDirection property to the next row or column. For example, if controls are being layed out from left to right (FlowDirection = LeftToRight) without WrapContents being set to true, then the controls will be added to the first row. Items that extend beyond the boundary of the FlowLayoutPanel will be clipped. ![]() When WrapContents is set to true, clipped controls are moved to the next row. ![]() Wraping the contents manuallyThe above example changes the WrapContents property at runtime. To do this simply set the value of the property to the desired value. this.flowLayoutPanel1.WrapContents = this.checkBox1.Checked; Breaking the flowWhen WrapContents is set to true you can force a control onto a new row or column, even if there is sufficient space remaining. This is done through the FlowBreak property which is added to each of the contained controls within a FlowLayoutPanel. If a control has its FlowBreak property set to true, then the next control will start on a new row or column. This can be done via the IDE or manually through code. flowLayoutPanel1.SetFlowBreak(button2, true); In the previous code, the next control after button2 will wrap. Margins and PaddingThe Padding property allows you to control the placement of controls within a FlowLayoutPanel. It specifies the spacing between the child controls and the border of the FlowLayoutPanel. The Margin property of the controls contained within the FlowLayoutPanel specifies how much space is between each control. Note Adding a control to a FlowLayoutPanel manuallyAdding a control to a FlowLayoutPanel is done in following manner: public void CreateMyFlowLayoutPanel()
{
FlowLayoutPanel flpPanel = new FlowLayoutPanel();
TextBox textBox1 = new TextBox();
Label label1 = new Label();
// Initialize the FlowLayoutPanel control.
flpPanel.Location = new Point(20,50);
flpPanel.Size = new Size(264, 150);
// Set the Borderstyle for the FlowLayoutPanel to three-dimensional.
flpPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
// Initialize the Label and TextBox controls.
label1.Text = "label1";
label1.Size = new Size(50, 20);
textBox1.Text = "";
textBox1.Size = new Size(150, 20);
// Add the Panel control to the form.
this.Controls.Add(flpPanel);
// Add the Label and TextBox controls to the Panel.
flpPanel.Controls.Add(label1);
flpPanel.Controls.Add(textBox1);
}
MSDN references
|