Open In App

How to set the Size of the FlowLayoutPanel in C#?

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. In FlowLayoutPanel control, you can set the size of the control in the form using Size Property. With the help of this property, you can set both the height and width of the control in pixels. You can set this property in two different ways:

1. Design-Time: It is the easiest way to set the size of the FlowLayoutPanel as shown in the following steps:



2. Run-Time: It is a little bit trickier than the above method. In this method, you can set the size of the FlowLayoutPanel control programmatically with the help of given syntax:



public System.Drawing.Size Size { get; set; }

The following steps show how to set the size of the FlowLayoutPanel dynamically:

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 f = new FlowLayoutPanel();
        f.Location = new Point(380, 124);
        f.Size = new Size(216, 57);
        f.Name = "Mycontainer";
        f.Font = new Font("Calibri", 12);
        f.FlowDirection = FlowDirection.RightToLeft;
        f.BorderStyle = BorderStyle.Fixed3D;
        f.ForeColor = Color.BlueViolet;
        f.Visible = true;
  
        // Adding this control to the form
        this.Controls.Add(f);
  
        // Creating and setting the 
        // properties of radio buttons
        RadioButton r1 = new RadioButton();
        r1.Location = new Point(3, 3);
        r1.Size = new Size(95, 20);
        r1.Text = "R1";
  
        // Adding this control 
        // to the FlowLayoutPanel
        f.Controls.Add(r1);
  
        RadioButton r2 = new RadioButton();
        r2.Location = new Point(94, 3);
        r2.Size = new Size(95, 20);
        r2.Text = "R2";
  
        // Adding this control to
        // the FlowLayoutPanel
        f.Controls.Add(r2);
  
        RadioButton r3 = new RadioButton();
        r3.Location = new Point(3, 26);
        r3.Size = new Size(95, 20);
        r3.Text = "R3";
  
        // Adding this control to
        // the FlowLayoutPanel
        f.Controls.Add(r3);
    }
}
}

Output:


Article Tags :
C#