Search code examples
c#flowlayoutpanel

How to center FlowLayoutPanel


I am trying to center a FlowLayoutPanel because I am using it my application in different computers. So I am having some problems because, for example, in my screen works fine but in another screen of a different computer the flowlayoutpanel is in the right side of the screen.

What I am doing to try to center this flowlayoutpanel is the following:

public MainPrinc()
        {
            InitializeComponent();
            flowlayoutPl.Location = new Point(this.ClientSize.Width / 2 - flowlayoutPl.Size.Width / 2, this.ClientSize.Height / 2 - flowlayoutPl.Size.Height / 2);
        }

But this is not working, what could I do? Thanks in advance.

EDIt: How looks in my screen:

My computer

How looks in another computer:

Another computer


Solution

  • Just put your code in the Load event handler like this:

    private void MainPrinc_Load(object sender, EventArgs e)
            {
                flowlayoutPl.Location = new Point(this.ClientSize.Width / 2 - flowlayoutPl.Size.Width / 2, this.ClientSize.Height / 2 - flowlayoutPl.Size.Height / 2);
            }