How to automatically move and resize buttons and labels when a form is expanded?


So I am using a form application that has buttons and labels in it (Picture) and I want to know how to make them re-size properly when I maximize the form. The anchor or/and dock property as in these questions: C# form auto resize window or Automatic resizing of the Windows Forms controls does not help because it expands only 1 item.

I need it to move and resize without going out of the original proportions. So like let's say I have 2 buttons above each other. I want them to stay always on the right side and they are each 10*12 pixels and 2 pixels from edge. When I expand the original window size three times, each button will still be 2 pixels from the edge but 30*36 pixels big.

You could put your buttons, etc in a tableLayoutPanel with one column and multiple rows(the number of element you want to place). Set the anchor of the tableLayout to "top" and "bottom". Then put one button/label in each row.

Define each row size with a percentage value:

tableLayoutPanel1.RowStyles[i].SizeType = SizeType.Percent;
tableLayoutPanel1.RowStyles[i].Height = 20.0F; //=20%

Finally set the anchor of each element to "top" and "bottom" too.