Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
607 views
in Technique[技术] by (71.8m points)

winforms - Visual Studio Designer added margin and padding to my form

I recently updated my development workstation to Windows 8.1 with a 4K monitor and went from Visual Studio 2010 to 2012. When I opened an existing project sweeping changes were made to Margin and Padding (were default).

Label - Margin(8, 0, 8, 0)
Button, DataGridView, TextBox, CheckBox - Margin(8, 7, 8, 7)
MenuStrip - Padding(16, 5, 0, 5)
GroupBox - Margin(8, 7, 8, 7) and Padding(8, 7, 8, 7)

The control Sizes are also bigger than before.

Is this because I'm using a 4K monitor with display scaling? If so, how can I control layout with this setup. Do I have to change my display resolution every time I want to edit the form?

Or is it something to do with VS 2012 or Win 8.1?

Any help is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The answer relates to DPI scaling. Basically, when something is edited in the designer other than at 96 DPI, it is scaled. When you save, the scaled values are saved. I was editing a form at 150 DPI.

I find the DPI support in Winforms to be pretty awkward but the wisdom seems to be to use the designer at a consistent DPI - i.e. on the same monitor and preferably at 96 DPI.

I have certainly found that it is difficult to get layout correct at higher DPI. I just can't see if things are properly aligned at higher DPI whereas I can see it clearly at 96 DPI. So, whether the advice to stick to 96 DPI is technically required or not I can't confirm but as a practice I find it visually necessary.

Here are some answers about how to build DPI Aware applications: https://stackoverflow.com/a/13228495/1439940, https://stackoverflow.com/a/4076259/1439940, https://stackoverflow.com/a/202172/1439940


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...