为什么我的 Visual Studio (VB.NET) 布局在我的家用计算机上的设计视图与运行时不同,但在我的工作计算机上是相同的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29447403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:57:35  来源:igfitidea点击:

Why is my Visual Studio (VB.NET) layout different in Design View vs. at run-time on my home computer, but identical on my work computer?

vb.netvisual-studiovisual-studio-2013windows-8

提问by Will

I've been developing a program with Windows Forms on my work computer in VB.NET using Visual Studio 2013. When I run it on my work computer, the forms at run-time look identical to the forms in design view - the same overall size, the same layout, etc. Here is what it looks like on my work computer - AND when I access my work computer over remote desktop from my home computer.

我一直在使用 Visual Studio 2013 在我的 VB.NET 工作计算机上开发一个带有 Windows 窗体的程序。当我在我的工作计算机上运行它时,运行时的窗体看起来与设计视图中的窗体相同 - 整体相同大小,相同的布局等。这是在我的工作计算机上的样子 - 当我从我的家用计算机通过远程桌面访问我的工作计算机时。

work computer

工作电脑

However, on my home computer, it looks different in design view than at run-time. The form in design view is smaller and labels are misaligned.

但是,在我的家用计算机上,它的设计视图与运行时不同。设计视图中的表单较小且标签未对齐。

home computer

家用电脑

Both computers are running Visual Studio 2013 with the same settings. I'm working on a larger monitor at home, but the fact that things look right when I access my work computer over Remote Desktop makes me think it's not my monitor.

两台计算机都使用相同的设置运行 Visual Studio 2013。我正在家里使用更大的显示器,但是当我通过远程桌面访问我的工作计算机时一切正常,这一事实让我认为这不是我的显示器。

My work computer is Windows 7 while my work computer is Windows 8.1.

我的工作计算机是 Windows 7,而我的工作计算机是 Windows 8.1。

Things I've tried:

我尝试过的事情:

  • Anchoring/docking the labels, but the layout ends up looking wrong
  • Changing the AutoScaleMode to DPI instead of Font, but that only changes the appearance at runtime, not in design view, and it still doesn't match design view.
  • 锚定/对接标签,但布局最终看起来不对
  • 将 AutoScaleMode 更改为 DPI 而不是 Font,但这只会在运行时更改外观,而不是在设计视图中,它仍然与设计视图不匹配。

Any ideas?

有任何想法吗?

回答by Will

I figured it out! It was a setting in Windows on my home computer. (Still unclear why it looked right via Remote Desktop, but maybe it uses the remote computer's settings instead of the local one's).

我想到了!这是我家用电脑上的 Windows 设置。(仍然不清楚为什么它通过远程桌面看起来是正确的,但它可能使用远程计算机的设置而不是本地计算机的设置)。

The solution was:

解决方案是:

  • Right click, choose "Screen Resolution"
  • Click "Make text and other items larger or smaller"
  • Check "Let me choose one scaling level for all my displays" and set size to "smaller - 100%"
  • 右击,选择“屏幕分辨率”
  • 单击“放大或缩小文本和其他项目”
  • 选中“让我为所有显示器选择一个缩放级别”并将大小设置为“更小 - 100%”

For some reason, on my home computer the size was set to 125%.

出于某种原因,在我的家用计算机上,大小设置为 125%。

setting to change

要更改的设置

回答by Flavio Rajta


After searching for a solution online this worked for me:


在网上搜索解决方案后,这对我有用:

this.AutoSize = false;<br>
this.AutoScaleMode = AutoScaleMode.Font;

I put this code on form load and the display remained the same.

我将此代码放在表单加载上,但显示保持不变。