Reputation: 3636
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?
Upvotes: 1
Views: 5849
Reputation: 84805
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 (e.g. 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:
TableLayoutPanel
, one after the other — FlowLayoutPanel
, etc.);Dock
and Anchor
properties of each control;AutoSize
and AutoSizeMode
properties of each control.Doing this correctly takes some practice, but makes your forms' layout much more robust.
Upvotes: 4