Pedery
Pedery

Reputation: 3636

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?

Upvotes: 1

Views: 5849

Answers (3)

Hacko
Hacko

Reputation: 1761

Set AutoScaleMode to Dpi on your UserControl or Form

Upvotes: 1

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:

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

Upvotes: 4

LarsTech
LarsTech

Reputation: 81675

Use the Anchor and Dock properties for the controls.

Upvotes: 0

Related Questions