自动缩放子控件当窗体最大化窗体、缩放、控件

2023-09-04 01:07:28 作者:时光深处

有没有一种方法,使一切,当最大化屏幕或更改分辨率自动调整在windowsFrom。

我发现这个手动的规模是正确的,但切换分辨率时,我有充分的时间来改变它。

  this.AutoScaleDimensions =新System.Drawing.SizeF(96F,96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
 

解决方案

有没有简单的开关,你可以preSS,使这个自动发生。自动缩放是用于解决一个完全不同的问题。你需要布置您的形式,其在考虑这个设计目标的控制。

在特定的,做的最好的方式,就是使用的 的TableLayoutPanel 控制的停靠,以补整个表单设置它的 码头属性以 DockStyle。填写。这将基本上成为布局网格,你用它来铺陈子控件,你希望出现在表单上。

然后,将每个正则控制了的TableLayoutPanel 控制的细胞内。设置 孩子的财产控制,表明你希望怎样为他们成长时的形式扩大(或缩小)。例如:

如果你希望一个控制水平增长时,窗体最大化时,你会想它锚定到其容器单元格的左右边缘。 要垂直成长,你会想它固定到电池的顶部和右边缘。 如果将它指向的所有的边缘,它会得到较大的在各个方向成长。 如果将它指向的没有边缘的的,控制将保持相同的大小,只是中心本身的细胞内。 vb.net Mdi 子窗体最小化后再最大化

这需要有点把玩得到正确的。例如,你会偶尔也要设置 Col​​umnSpan 和/或 ROWSPAN 控件的的TableLayoutPanel 控制内部性能,以确保他们安排你所希望的方式,特别是相对于表单上显示的其他控件。

但它只是做你的愿望的唯一途径,它的确实的工作得很好,一旦你得到它成立。

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 when switching resolution I have to change it every time.

this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;

解决方案

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.