Search code examples
vb.netvisual-studio-designer

How to maintain control in center with anchor(left,right)/dock(fill) and maximum width


Let's say we have form with docked GroupBox. GroupBox have docked TableLayoutPanel with 2 rows (50% height each). Each row have Button. I want this buttons to be centered in TableLayoutPanel cells, expanding with form but also have a maximum width.

Example form:

ex_form_img

If I use anchor(left,right) or dock(fill) and then set maximum width for buttons, they stay on left side of cells. Is there a way to do what I want (have button in center when reached max width) using only designer?


Solution

    • turn OFF all anchors for each button to keep it in the center of the parent container without changing their size

      OR

    • center each button and then turn ON all its anchors to keep it in the center expanding with the parent container

    But you cannot achieve limiting the button size together with centering. You can do it only dynamically, through code.