C# WinForms Vertical Alignment for TextBox, etc

前端 未结 5 1396
天涯浪人
天涯浪人 2020-12-03 12:34

I\'m working on a project updating their WinForms application UI to be more consistent with sizes. TextBox and ComboBox controls have different heights by default, even wit

5条回答
  •  心在旅途
    2020-12-03 12:50

    Did you try the TableLayoutPanel solution to provide vertical alignment? You can then adjust the height as you wish, dynamically through events, OR by using a fixed value, OR with the TableLayoutPanel's row AutoSize feature.

    Just add a TableLayoutPanel to contain the TextBox. This TableLayoutContainer has 1 column and 3 rows. The TextBox must be placed in the second row. The first and the last rows are set to 50% height (they actually use only the "remaining height"). After you placed the TextBox in the second row, this row can then be set to an absolute value of your choice or to Auto-size.

    The TableLayoutPanel has its own control of width and height. But if you are placing this TableLayoutPanel inside a cell of another TableLayoutPanel, just remember to set the property Auto-size of your new TableLayoutPanel to true, so it can adjust itself to the size of the cell.

    In general, TableLayoutPanels are of great help for your design, I definitely recommend using them.

提交回复
热议问题