How to center panel inside groupbox?

0

How can I centralize panel1 in groupbox ?

Follow the code below:

private void Form1_Load(object sender, EventArgs e)
{
    // aqui defino novo size do panel1
    panel1.Size = new Size(591, 423);
}

The problem is that panel1 is not centralized.

Any solution?

    
asked by anonymous 24.11.2017 / 00:34

2 answers

1

Issue resolved:

panel1.Location = new Point(
    groupBox1.Width / 2 - panel1.Size.Width / 2,
    groupBox1.Height / 2 - panel1.Size.Height / 2);
panel1.Anchor = AnchorStyles.None;
    
24.11.2017 / 00:44
0

You can also align by .Top and .Left properties depending on your needs.

Alignment within a control or component is a fairly easy thing. Come on!

Knowing that the center of the Container is half its width .Width / 2 and half its height .Heigth / 2

control.Top = (Container.Heigth / 2) - (control.Heigth - 2);

control.Left = (Container.Width / 2) - (control.width - 2);

Note: Container is nothing more than your container.

    
28.11.2017 / 16:13