Search code examples
winformsvisual-studio-2008windows-7dpi

Why are my dialog boxes too small on some (but not all) Windows7 computers?


I'm starting to test a Winforms (using VS2008) app on Windows 7, and am seeing a strange problem.

It ran fine on the first couple of Win7 installations, but on the next two, many of my dialogs are too small, clipping the content by about 30%.

The app was developed on WinXP, and have not seen this problem on any of the XP installations!

Just starting to investigate the problem - don't have any details on differences between the systems that work and those that don't yet.

Edit

According to Kate's comment to one of the answers, Win7 will sometimes change to a custom text size when a new monitor is installed. The machine with the problem has a big, widescreen monitor, and when we checked (Control Panel + Display + Custom Text Size) - sure enough - the custom text size was set to 125%. Setting it to 100% made the problem go away.

I was then able to replicate the problem on WinXP by setting the text size to 125%.

So the question now becomes - how do you ensure a Winforms app is "custom text size independent"?

/Edit

As suggested, here are some screen shots. 1st one is from a Windows 7 computer, 2nd one is from my WinXP development system.

Windows 7

Windows XP


Solution

  • Although both screen DPI and Themes can change the size of controls, that is not the problem here because in your screen shots the window chrome and non-text control sizes are unchanged. The problem is you are not taking custom font sizes into account.

    If you wanted to move controls around to fix them into a fixed form size you would have to perform calculations using the Control.AutoScaleDimensions property of your controls. That is a lot of work, don't do that.

    Instead, lay out your controls using absolute coordinates and enlarge your form to contain the results. Set your forms' AutoScaleMode = AutoScaleMode.Font.