C# | FlowLayoutPanel Class

15 Nov, 2021
In Windows Forms, FlowLayoutPanel control is used to arrange its child controls in a horizontal or vertical flow direction. Or in other words, FlowLayoutPanel is a container which is used to organize different or same types of controls in it either horizontally or vertically. The FlowLayoutPanel class is used to represent windows flow layout panel and also provide different types of properties, methods, and events. It is defined under System.Windows.Forms namespace. In C#, you can create a FlowLayoutPanel in the windows form by using two different ways:
1. Design-Time: It is the easiest way to create a FlowLayoutPanel control as shown in the following steps:
Step 1: Create a windows form as shown in the below image:Visual Studio -> File -> New -> Project -> WindowsFormApp
Step 2: Next, drag and drop the FlowLayoutPanel control from the toolbox to the form as shown in the below image:
Step 3: After drag and drop you will go to the properties of the FlowLayoutPanel to modify FlowLayoutPanel according to your requirement.Output:
Output:
2. Run-Time: It is a little bit trickier than the above method. In this method, you can create a FlowLayoutPanel programmatically with the help of syntax provided by the FlowLayoutPanel class. The following steps show how to set the create FlowLayoutPanel dynamically:
Step 1: Create a FlowLayoutPanel using the FlowLayoutPanel() constructor is provided by the FlowLayoutPanel class.// Creating a FlowLayoutPanel
FlowLayoutPanel fl = new FlowLayoutPanel(); 

// Creating a FlowLayoutPanel
FlowLayoutPanel fl = new FlowLayoutPanel(); 

Step 2: After creating a FlowLayoutPanel, set the property of the FlowLayoutPanel provided by the FlowLayoutPanel class.// Setting the location of the FlowLayoutPanel
 fl.Location = new Point(380, 124); 

// Setting the size of the FlowLayoutPanel
        fl.Size = new Size(216, 57); 

// Setting the name of the FlowLayoutPanel
        fl.Name = "Mycontainer"; 

// Setting the font of the FlowLayoutPanel
        fl.Font = new Font("Calibri", 12); 

// Setting the flow direction of the FlowLayoutPanel
        fl.FlowDirection = FlowDirection.RightToLeft; 

// Setting the border style of the FlowLayoutPanel
        fl.BorderStyle = BorderStyle.Fixed3D; 

// Setting the foreground color of the FlowLayoutPanel
        fl.ForeColor = Color.BlueViolet; 

// Setting the visibility of the FlowLayoutPanel
        fl.Visible = true; 

// Setting the location of the FlowLayoutPanel
 fl.Location = new Point(380, 124); 

// Setting the size of the FlowLayoutPanel
        fl.Size = new Size(216, 57); 

// Setting the name of the FlowLayoutPanel
        fl.Name = "Mycontainer"; 

// Setting the font of the FlowLayoutPanel
        fl.Font = new Font("Calibri", 12); 

// Setting the flow direction of the FlowLayoutPanel
        fl.FlowDirection = FlowDirection.RightToLeft; 

// Setting the border style of the FlowLayoutPanel
        fl.BorderStyle = BorderStyle.Fixed3D; 

// Setting the foreground color of the FlowLayoutPanel
        fl.ForeColor = Color.BlueViolet; 

// Setting the visibility of the FlowLayoutPanel
        fl.Visible = true; 

Step 3: And last add this FlowLayoutPanel control to the form and also add other controls on the FlowLayoutPanel using the following statements:// Adding a FlowLayoutPanel
// control to the form
this.Controls.Add(fl);
and 

// Adding child controls 
// to the FlowLayoutPanel
fl.Controls.Add(f1);
Example:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;  namespace WindowsFormsApp50 {  public partial class Form1 : Form {      public Form1()    {        InitializeComponent();    }      private void Form1_Load(object sender, EventArgs e)    {        // Creating and setting the        // properties of FlowLayoutPanel        FlowLayoutPanel fl = new FlowLayoutPanel();        fl.Location = new Point(380, 124);        fl.Size = new Size(216, 57);        fl.Name = "Myflowpanel";        fl.Font = new Font("Calibri", 12);        fl.FlowDirection = FlowDirection.RightToLeft;        fl.BorderStyle = BorderStyle.Fixed3D;        fl.ForeColor = Color.BlueViolet;        fl.Visible = true;          // Adding this control to the form        this.Controls.Add(fl);          // Creating and setting the        // properties of radio buttons        RadioButton f1 = new RadioButton();        f1.Location = new Point(3, 3);        f1.Size = new Size(95, 20);        f1.Text = "R1";          // Adding this control        // to the FlowLayoutPanel        fl.Controls.Add(f1);          RadioButton f2 = new RadioButton();        f2.Location = new Point(94, 3);        f2.Size = new Size(95, 20);        f2.Text = "R2";          // Adding this control        // to the FlowLayoutPanel        fl.Controls.Add(f2);          RadioButton f3 = new RadioButton();        f3.Location = new Point(3, 26);        f3.Size = new Size(95, 20);        f3.Text = "R3";          // Adding this control        // to the FlowLayoutPanel        fl.Controls.Add(f3);    }}}Output:
// Adding a FlowLayoutPanel
// control to the form
this.Controls.Add(fl);
and 

// Adding child controls 
// to the FlowLayoutPanel
fl.Controls.Add(f1);

Example:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;  namespace WindowsFormsApp50 {  public partial class Form1 : Form {      public Form1()    {        InitializeComponent();    }      private void Form1_Load(object sender, EventArgs e)    {        // Creating and setting the        // properties of FlowLayoutPanel        FlowLayoutPanel fl = new FlowLayoutPanel();        fl.Location = new Point(380, 124);        fl.Size = new Size(216, 57);        fl.Name = "Myflowpanel";        fl.Font = new Font("Calibri", 12);        fl.FlowDirection = FlowDirection.RightToLeft;        fl.BorderStyle = BorderStyle.Fixed3D;        fl.ForeColor = Color.BlueViolet;        fl.Visible = true;          // Adding this control to the form        this.Controls.Add(fl);          // Creating and setting the        // properties of radio buttons        RadioButton f1 = new RadioButton();        f1.Location = new Point(3, 3);        f1.Size = new Size(95, 20);        f1.Text = "R1";          // Adding this control        // to the FlowLayoutPanel        fl.Controls.Add(f1);          RadioButton f2 = new RadioButton();        f2.Location = new Point(94, 3);        f2.Size = new Size(95, 20);        f2.Text = "R2";          // Adding this control        // to the FlowLayoutPanel        fl.Controls.Add(f2);          RadioButton f3 = new RadioButton();        f3.Location = new Point(3, 26);        f3.Size = new Size(95, 20);        f3.Text = "R3";          // Adding this control        // to the FlowLayoutPanel        fl.Controls.Add(f3);    }}}
Output:
CSharp-Windows-Forms-Namespace
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.