Strange behavior in Windows Forms application running at different DPI settings
I have a Windows Forms application (written in vs2010/C# against .NET framework 3.5) with one main form. It was designed at Win7's 100% DPI setting (I believe that's 96 dpi). When switching the computer to 150%, everything appears to scale just fine and all proportions are kept.
However, when I switch to 125%, some of the controls suddenly don't scale and appear to be as big as they would be at 100%. This messes up the whole layout, and hides some controls from the user.
Is there any kind of 开发者_如何转开发logical explanation as to the large difference in behavior between the 125% and 150% settings?
Also, is there a quicker way to test this? Having to log off and back in again every time I switch is quickly becoming annoying.
There's no simple explanation for what you observe.
A cheap way to test this without having to go through the painful login cycle is to change the form's Font property in the OnLoad method:
protected override void OnLoad(EventArgs e) {
this.Font = new Font(this.Font.FontFamily, this.Font.SizeInPoints * 120f / 96f);
base.OnLoad(e);
}
Look at form's AutoScaleMode. It is probably set to Font or Dpi
Add to John Arlen's post:
You may also want to allow the form to Grow and Shrink, using the AutoSizeMode.
With respect to "Also, is there a quicker way to test this? Having to log off and back in again every time I switch is quickly becoming annoying."
Best thing is to use a Virtual Machine with a different DPI settings. You just run your application from the 'real' machine.
精彩评论