Reputation: 4359
I have a panel, i want to align it vertically middle within a panel, the pic shows what i want
Any one know how to do that?
Upvotes: 0
Views: 651
Reputation: 398
Align a control in parent vertically:
InsidePanel.Location = new Point(
0, (OutsidePanel.Height - InsidePanel.Height) / 2
);
Align a control in parent horizontally:
InsidePanel.Location = new Point(
(OutsidePanel.Width - InsidePanel.Width) / 2, 0
);
If you do have form resizing, you will need to make sure this is added to you resize event handler to make sure the controls stay centered.
Upvotes: 1
Reputation: 27009
You can use a TableLayoutPanel control.
TableLayoutPanel
onto your formDock
property to Fill
Columns
collection because by default you will get 2 columns.Row
to your panel because by default you will get 2.Then:
Dock
property to Fill
Set the sizes for the rows for the TableLayoutPanel
as shown in the following screenshot:
Upvotes: 0