简体   繁体   中英

Windows forms controls' sizes changes when display settings change

I'm working on a Windows Forms project. In this project the controls' sizes are set in the designer and autosize is turned off. Yet when the display settings in Windows 7 are set to medium (125%) or large (150%) , the controls change size. How can I prevent this behavior?

Most likely you could turn off this behaviour by setting your form's AutoScaleMode property to AutoScaleMode.None .

That being said, don't just turn auto-scaling off, because it's most likely a good thing! It makes your forms work at various resolutions and font scale settings. For example, if you design your forms but forget about users with impaired vision (eg people who increase the system font scaling to unusually high percentages), chances are that your form might still work, thanks to auto-scaling.

As the other answers suggest, instead of specifying the positions and sizes of each control in terms of fixed pixel values and then turning off auto-scaling, use automatic layout techniques:

  • putting controls inside the various container elements for arranging controls (in a grid – TableLayoutPanel , one after the other — FlowLayoutPanel , etc.);
  • setting the Dock and Anchor properties of each control;
  • setting the AutoSize and AutoSizeMode properties of each control.

Doing this correctly takes some practice, but makes your forms' layout much more robust.

使用控件的Anchor和Dock属性。

在UserControl或Form上将AutoScaleMode设置为Dpi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM