VS 2010 在未进行任何更改时更新 Designer.cs [英] VS 2010 updates Designer.cs when no changes are made

查看:27
本文介绍了VS 2010 在未进行任何更改时更新 Designer.cs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在设计器视图中打开表单时,VS 2010 似乎正在更新我的表单的 Designer.cs 文件.

VS 2010 seems to be updating my form's designer.cs file when I open the form in designer view.

例如,假设我有一个带有 System.Windows.Forms.Label 类型标签的表单,并且我已经创建了标签,以便设计器文件具有(自动生成的代码)

For example, say I have a form with a label of type System.Windows.Forms.Label and I had created the label such that the designer file has (auto generated code)

this.myLabel.AutoSize = true;
this.myLabel.Font = new System.Drawing.Font("Tahoma", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.myLabel.Location = new System.Drawing.Point(**25, 63**);
this.myLabel.Name = "myLabel";
this.myLabel.Size = new System.Drawing.Size(**101, 13**);
this.myLabel.TabIndex = 1;
this.myLabel.Text = "A simple windows label.";

当我关闭设计器视图并再次打开它时,VS 2010 会有时将其更改为

when I close out of designer view and open it again, VS 2010 will sometimes alter it to

this.myLabel.AutoSize = true;
this.myLabel.Font = new System.Drawing.Font("Tahoma", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.myLabel.Location = new System.Drawing.Point(**29, 78**);
this.myLabel.Name = "myLabel";
this.myLabel.Size = new System.Drawing.Size(**124, 17**);
this.myLabel.TabIndex = 1;
this.myLabel.Text = "A simple windows label.";

当我除了打开文件之外什么都没做.

when I've not done anything other than open the file.

有谁知道为什么会这样?有没有其他人遇到过这样的事情?

Does anyone know why this is happening? Has anyone else experienced anything like this?

推荐答案

功能,而不是错误.该表单最初是在一台其视频适配器每英寸点数设置为 96 的机器上设计的.您的机器具有不同的 DPI,120.在现代版本的 Windows 上很容易更改,您选择了 125%(中)设置在控制面板 + 显示中.

Feature, not a bug. The form was originally designed on a machine that had its video adapter dots-per-inch setting at 96. Your machine has a different DPI, 120. Very easy to change on modern versions of Windows, you picked the 125% (Medium) setting in Control Panel + Display.

不同的 dpi 设置会影响您使用的字体大小.在您的代码片段中有一个可见,它是 8.25 分.一点是 1/72 英寸.所以文字原来是 8.25 * 1/72 = 0.114583 英寸高.dpi 为 96,即 0.114583 x 96 = 11 像素.请注意,这也解释了为什么将额外的 0.25 添加到点大小的原因,它是一个不错的整数.

A different dpi setting affects the size of the fonts you use. There's one visible in your code snippet, it is 8.25 points. One point is 1/72 inch. So the text was originally 8.25 * 1/72 = 0.114583 inches high. With the dpi at 96, that's 0.114583 x 96 = 11 pixels. Note how this also explains why you got the extra 0.25 added to the point size, it made a nice round number.

但现在你的 dpi 是 120,文本将是 8.25 x 1/72 x 120 = 14 像素.文本变大了,你的控件也需要变大,否则它会剪掉文本,剪掉下行.

But now your dpi is 120, the text will be 8.25 x 1/72 x 120 = 14 pixels. The text got bigger, your control needs to get bigger too or it will clip the text, shearing off the descenders.

这是在您加载表单时自动完成的.基本属性是 AutoScaleMode,默认设置为 Font.和 AutoScaleDimensions,你会发现它被分配在 InitializeComponent() 方法的顶部.那就是记住原始 DPI 设置的那个人.

This was done automatically when you loaded the form. The essential properties are AutoScaleMode, set to Font by default. And AutoScaleDimensions, you'll find it assigned at the top of the InitializeComponent() method. That's the one that remembered what the original DPI setting was.

这也将发生在您用户的机器上.请确保表单自动缩放正确.如果您的控件具有不同的字体大小,您可能会遇到一些麻烦.只需将表单检查回源代码管理,这样就不会再次发生这种重新缩放.

This is going to happen on your user's machine as well. Do make sure that the form auto-scaled properly. You may have some trouble if you have controls that have a different font size. And just check the form back into source control so this rescaling doesn't happen again.

这篇关于VS 2010 在未进行任何更改时更新 Designer.cs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆