[英]C# and Windows Forms application form size
I was working on a Windows Forms application today that was functioning correctly. 今天,我正在使用Windows Forms应用程序,该应用程序运行正常。 When I changed the font size of some buttons, textboxes and labels the form zoomed in and now it is far too big on runtime, and I can't figure out how to change the size back.
当我更改某些按钮,文本框和标签的字体大小时,表单被放大了,现在它在运行时变得太大了,我不知道该如何改变大小。
The first image shows the form designer and the second shows the form running hard to show as it is bigger than the screen size. 第一个图像显示表单设计器,第二个图像显示运行难以显示的表单,因为它大于屏幕大小。
You should change the size value or ClientSize of the form, 您应该更改表单的大小值或ClientSize,
this.Size = new Size(200, 200);
or 要么
this.ClientSize = new Size(200, 200);
Or you can view the form in Visual Studio and click on the side of it and play with its size. 或者,您可以在Visual Studio中查看表单,然后单击它的侧面并播放其大小。
See: How do I resize a Windows Forms form in C#? 请参阅: 如何在C#中调整Windows窗体的大小?
When designing a form, keep in mind that the screen DPI, user font settings (zoom, etc), and other factors can cause a form to change size. 设计表单时,请记住屏幕DPI,用户字体设置(缩放等)和其他因素可能会导致表单更改大小。 It's a good idea to make your forms handle such changes gracefully.
让表单优雅地处理这些更改是个好主意。
To keep things visible, use layout controls. 要保持可见,请使用布局控件。 In the Toolbox, they are under "Containers".
在工具箱中,它们位于“容器”下。 Based on your screenshot, I would assume a
TableLayoutPanel
would work best. 根据您的屏幕截图,我认为
TableLayoutPanel
效果最佳。 You might want to use a SplitContainer
that has its Orientation
set to Vertical and IsSplitterFixed
set to True. 您可能希望使用其
Orientation
设置为Vertical且IsSplitterFixed
设置为True的SplitContainer
。 You may need to nest some things depending on how exactly you want it laid out. 你可能需要根据你想要的布局来嵌套一些东西。
Once you have done that, you can use the Anchor
and Dock
properties of the controls to position and size them within the containers. 完成后,您可以使用控件的
Anchor
和Dock
属性在容器中定位和调整它们的大小。
When all of this is put together, you can resize a form, and the controls will stay in place, move around, change size, and/or do anything else that they and their containers are set to do. 当所有这些组合在一起时,您可以调整表单的大小,控件将保持原位,移动,更改大小,和/或执行他们及其容器设置的任何其他操作。 No additional coding to control size would be needed.
不需要额外的编码来控制大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.