Automatically scaling child controls when a form is maximized

后端 未结 1 1142
谎友^
谎友^ 2021-01-23 03:39

Is there a way to make everything automatically scale on a windowsFrom when maximizing the screen or changing resolution.

I found this to manual scale it correct but whe

相关标签:
1条回答
  • 2021-01-23 04:03

    There's no simple switch you can press to make this happen automatically. Auto-scaling is for solving a very different problem. You need to lay out your form and its controls with this design goal in mind.

    In particular, the best way to do it is to use a TableLayoutPanel control docked to "fill" your entire form—set its Dock property to DockStyle.Fill. This will essentially become the "layout grid" that you use to lay out the child controls you wish to appear on the form.

    Then, place each of your regular controls inside of the "cells" of that TableLayoutPanel control. Set the Anchor property of the child controls to indicate how you wish for them to grow when the form is expanded (or shrunk). For example:

    • If you wish a control to grow horizontally when the form is maximized, you will want to anchor it to the left and right edges of its container cell.
    • To grow vertically, you will want to anchor it to the top and right edges of the cell.
    • If you anchor it to all edges, it will get larger by growing in all directions.
    • If you anchor it to none of the edges, the control will stay the same size and simply center itself inside of the cell.

    This takes a bit of futzing to get right. For example, you will occasionally have to set the ColumnSpan and/or RowSpan properties of controls inside of the TableLayoutPanel control to ensure that they arrange the way you want them to, particularly relative to other controls displayed on your form.

    But it is just about the only way to do what you desire, and it does work very well once you get it set up.

    0 讨论(0)
提交回复
热议问题