简体   繁体   English

每次打开窗体时,如何阻止Visual Studio放大控件?

[英]How do I stop Visual Studio from enlarging controls every time I open a windows form?

I have one windows form file that each time I open it in Visual Studio it increases the size of the controls within the designer file. 我有一个Windows窗体文件,每次我在Visual Studio中打开它时,它会增加设计器文件中控件的大小。 If I save the form, close it in the editor, and open it again, then the controls are all a little larger than before. 如果我保存表单,在编辑器中关闭它,然后再次打开它,然后控件都比以前大一些。 I can see that the size properties on the controls are all increasing within the designer file. 我可以看到控件上的大小属性都在设计器文件中增加。

Can anyone explain to me how to fix this behavior? 任何人都可以向我解释如何解决这个问题?

I've had problems with visual studio when running on windows 8 with an HD res laptop vs a regular 1280 x 800 one 我在使用HD res笔记本电脑和普通1280 x 800笔记本电脑的Windows 8上运行时遇到了Visual Studio的问题

The windows default on a fresh install for the HD laptop was to increase font size in windows programs by 25% 用于高清笔记本电脑的全新安装窗口是为了将Windows程序中的字体大小增加25%

Look under Screen Resolution -> Make text or other items larger or smaller -> Select 'Let me choose one scaling level for all my displays' to see the setting. 在屏幕分辨率下查看 - >使文本或其他项目更大或更小 - >选择“让我为所有显示选择一个缩放级别”以查看设置。 125% in my case. 在我的情况下125%。

Visual studio seems to set the form or controls AutoScaleMode setting based on the setting above. Visual Studio似乎根据上面的设置设置表单或控制AutoScaleMode设置。

In the form designer: On low res laptop this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 在表单设计器中:在低分辨率笔记本电脑上.AutoScaleDimensions = new System.Drawing.SizeF(6F,13F);

Hi res this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); 嗨res this.AutoScaleDimensions = new System.Drawing.SizeF(7F,16F);

To elaborate on my comment, when the designer loads/saves your form, it is going to call the getters/setters on the public properties of your Form and the Form's controls. 要详细说明我的评论,当设计者加载/保存表单时,它将调用表单和表单控件的公共属性上的getters / setter。

This means that if you've overridden a property of the form, and accessing/setting said property has a side effect of resizing a control, that size adjustment will be reflected in the designer. 这意味着如果您覆盖了表单的属性,并且访问/设置所述属性具有调整控件大小的副作用,则该大小调整将反映在设计器中。 Then when you save the form, that new size is persisted to the designer-generated code. 然后,当您保存表单时,该新大小将持久保存到设计器生成的代码中。 Each time you reopen the form, this adjustment would occur. 每次重新打开表单时,都会进行此调整。

This would also apply to event handlers for properties that are being set within the designer-generated code. 这也适用于在设计器生成的代码中设置的属性的事件处理程序。

Just lock your controls so that you can't accidentally move or resize them. 只需锁定您的控件,以便您不会意外移动或调整它们的大小。

Just open the form designer, right click and from the context menu choose "Lock Controls". 只需打开表单设计器,右键单击并从上下文菜单中选择“锁定控件”。

在此输入图像描述

As to why Visual Studio is resizing them automatically, I can only guess. 至于为什么Visual Studio会自动调整它们的大小,我只能猜测。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我使用Designer向表单添加新控件时,如何阻止visual studio更改WPF表单中控件的属性? - How to stop visual studio from changing properties of controls in WPF form when I add a new control to form using Designer? WinForms - 为什么每次在Visual Studio中打开它时C#表单都会运行SQL? - WinForms - why does C# form run the SQL in it every time I open it in Visual Studio? 如何将XtraReport连接到Visual Studio 2010上的Windows窗体 - How do I connect XtraReport to windows form on Visual Studio 2010 我如何阻止 Visual Studio 2017 在保存时构建 - How do i stop visual studio 2017 from building on save 如何阻止 Visual Studio 2010 在模板中自动生成控件? - How can I stop Visual Studio 2010 from auto generating controls in a template? 如何将控制台应用程序中的变量值传递给 C# 中的 windows 表单应用程序(Visual Studio) - How do i pass a variable value from Console application to windows form application in C# (visual studio) 如何停止Visual Studio 2015连接到项目加载时的每个连接字符串? - How do I stop Visual Studio 2015 connecting to every connection string on project load? 在绘制控件后,如何将光标放回Visual Studio 2010 RC Windows窗体设计器中? - How do I get the cursor back in Visual Studio 2010 RC Windows Forms designer after drawing controls? 初始化 C# Visual Studio Windows 窗体应用程序后,如何更改窗体的视觉效果? - How do I change the visual of a form after it has Initialized C# Visual Studio Windows Form App? 如何将Metro UI控件添加到visual studio中的工具箱? - How do I add the Metro UI controls to the toolbox in visual studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM