Sunday 8 May 2011

Flow Layout Panel in C#

Flow Layout Panel
The 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.
Useful properties

 AutoScroll - This property when set to true, allows scroll bars to be displayed.

 BackColor - The background color of the Panel is defaulted to System.Drawing.SystemColors.Control, but this can be set to any color you like.

 BackgroundImage - Instead of a single color, an image can be displayed as the background.

 BorderStyle - This property determines if the panel is outlined with no visible border (None), a plain line (FixedSingle), or a shadowed line (Fixed3D).

 Controls - Gets the collection of controls contained within the control.

  Enabled - If this property is set to false, the controls contained within the Panel will also be disabled.

 FlowDirection - Gets or sets a value indicating the flow direction of the FlowLayoutPanel control. This property takes a value from the FlowDirection enumeration, the default value is LeftToRight:
              BottomUp - Elements flow from the bottom of the design surface to the top.
              LeftToRight - Elements flow from the left edge of the design surface to the right.
              RightToLeft - Elements flow from the right edge of the design surface to the left.
              TopDown - Elements flow from the top of the design surface to the bottom.

 TabIndex - Gets or sets the tab order of the control within its container.

 TabStop - Gets or sets a value indicating whether the user can give the focus to this control using the TAB key.

 WrapContents - Gets or sets a value indicating whether the FlowLayoutPanel control should wrap its contents or let the contents be clipped.


Useful methods

   GetFlowBreak - Returns a value that represents the flow-break setting of the FlowLayoutPanel control.

   SetFlowBreak - Sets the value that represents the flow-break setting of the FlowLayoutPanel control.

Example-  First drag and drop FloyLayout Panel and add controls like- label->textbox->label->textbox->button. You will see that your controls are adding from left to right because by default Flawlayout Panel Property i.e.. FlowDirection is left to right. So for understanding this i have taken one checkbox to make wrapping controls in Flow layout panel. By default it is false in Flow layout panel.
   

Code for check box event for wrapping control-

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            flowLayoutPanel1.WrapContents = true;
        }

         

No comments:

Post a Comment