1

Often I will create a winforms app and everything looks great when I run it. Then I go to a user's computer and I see that labels are crunched, fonts are bigger and causing text to be cut off etc. What is going on? How can I prevent this?

I especially see this on newer windows OS', i.e. Windows 7 etc. How can I make the form look the same (or at least good) for all users, on multiple windows OS versions?

richard
  • 12,263
  • 23
  • 95
  • 151

1 Answers1

2

If the UI is getting messed up because the fonts on the system are bigger or the DPI of the system is different from what you expected there are a couple of things you should do:

  • do not use fixed coordinates and sizes
  • do use docking and anchoring to position and size controls
  • do use AutoSize to size controls according to their content
  • do use Graphics.MeasureString() to calculate the size of strings instead of assuming a fontsize

EDIT

Of course it is also possible to distribute fonts (if legal) to make sure the correct/expected fonts are available but you will still need to anticipate various DPI settings.

Emond
  • 50,210
  • 11
  • 84
  • 115
  • So the dpi could mess it up and make text that used to fit into a particular space no longer fit? I would expect everything to scale together with the dpi... – richard Jun 14 '12 at 06:26
  • Yes, I would too but unfortunately not all developers accounted for DPI changes. Just change your DPI and startup Visual Studio. Whenever there are fixed sizes expressed in pixels the user will suffer. Have a look at this question too: http://stackoverflow.com/questions/50528/font-size-independent-ui-everything-broke-when-i-switched-to-120-dpi – Emond Jun 14 '12 at 06:36