简体   繁体   English

C#和Windows Forms应用程序表单大小

[英]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. 完成后,您可以使用控件的AnchorDock属性在容器中定位和调整它们的大小。

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.

相关问题 如何在 C# Windows 窗体应用程序中修复窗体大小而不让用户更改其大小? - How can I fix the form size in a C# Windows Forms application and not to let user change its size? c#Windows窗体应用程序窗体问题 - c# Windows form application forms problem Windows Forms C# 应用程序 - 当用户为操作系统字体大小选择 125% 或 150% 时,设置表单控件的字体大小以适应屏幕? - Windows Forms C# application - Set font size of form controls to fit the screen when a user choose 125% or 150% for the OS font size? 单击Windows窗体应用程序C#按钮,关闭特定的窗体 - Windows Forms Application C# button on click close specific form C#Windows窗体应用程序->在多个窗体之间切换 - C# Windows Form Application --> Switching Between Multiple Forms 如何通过调整大小来修复C#Windows窗体应用程序的大小 - How to fix the size of a C# Windows Form Application from resizing Windows在C#中形成自动大小 - Windows forms auto size in c# C#Windows窗体应用程序 - C# windows form application 当我们的C#应用​​程序中有多个Windows窗体时,如何制作一个窗体作为打开窗体 - When we have multiple windows forms in our C# application, how to make one form as opening form C#Windows窗体。 登录表单 - C# Windows Forms. Login form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM