Why is my Visual Studio (VB.NET) layout different

2019-09-24 02:07发布

问题:

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.

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.

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.

My work computer is Windows 7 while my work computer is 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.

Any ideas?

回答1:

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).

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%"

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



回答2:


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.