<p>So I was reading those Windows Vista UI guidelines someone linked to in another question, and they mentioned that you should be able to survive a switch to 120 DPI. Well, I fire up my handy VM with my app installed, and what do we get... AAAAGH!!! MASSIVE UI FAIL!</p>

<p>Everything's all jumbled: some containers aren't big enough for their text; some controls that were positioned "next to each other" are now all squished together/spread apart; some buttons aren't tall enough; my <code>ListView</code> columns aren't wide enough... eeek.</p>

<p>It sounds like a completely different approach is in order. My previous one was basically using the VS2008 Windows Forms designer to create, I guess, a pixel-based layout. I can see that if I were to stick with Windows Forms, <code>FlowLayoutPanel</code>s would be helpful, although I've found them rather inflexible in the past. They also don't solve the problem where the containers (e.g. the form itself) aren't big enough; presumably there's a way to do that? Maybe that <code>AutoSize</code> property?</p>

<p>This might also be a sign that it's time to jump ship to WPF; I'm under the impression that it's specifically designed for this kind of thing.</p>

<p>The basic issue seems to come down to these:</p>

<ul>
<li>If I were to stick with Windows Forms, what are all the tricks to achieving a font-size-independent layout that can survive the user setting his fonts large, or setting the display to 120 DPI?</li>
<li>Does WPF have significant advantages here, and if so, can you try to convince me that it's worth the switch?</li>
<li>Are there any general "best-practices" for font-size-independent layouts, either in the .NET stack or in general?</li>
</ul>

[{'answer_id': 50535, 'author': 'Sören Kuklau', 'author_id': 1600, 'author_profile': 'https://Stackoverflow.com/users/1600', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n  <p>If I were to stick with Windows Forms, what are all the tricks to achieving a font-size-independent layout that can survive the user setting his fonts large, or setting the display to 120 DPI?</p>\n</blockquote>\n\n<p>For one, <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.autoscalemode.aspx" rel="nofollow noreferrer">AutoScaleMode</a> may be your friend.</p>\n'}, {'answer_id': 50601, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 2, 'selected': False, 'text': '<p>In general, the problem is one of using two different "constants" for form layout, and then changing one of those constants without changing the other.</p>\n\n<p>You are using pixels for your form entities, and points (basically inches) to specify font size.  Pixels and points are related by DPI, so you change the DPI and suddenly your pixel fixed values don\'t line up with your point fixed values.</p>\n\n<p>There are packages and classes for this, but at the end of the day you must choose one unit or the other, or scale one of the units according to the changing constant.</p>\n\n<p>Personally, I\'d change the entities on the form into inches.  I\'m not a C# person, so I don\'t know if this is supported natively, or if you have to perform some dynamic form sizing on application startup.</p>\n\n<p>If you have to do this in your software,  then go ahead and size everything normally (say, to your usual 96 DPI).</p>\n\n<p>When your application starts, verify the system is at 96 DPI before you show your forms.  If it is, great.  If not, then set a variable with the correction factor, and scale and translate (modify both the location and size) of each entity before you show the form.</p>\n\n<p>The ultimate, though, would be to specify everything in inches or points (a point is 1/72 of an inch) and let the OS deal with it.  You might have to deal with corner cases (an outdoor screen with a correctly set DPI would show your application in a few pixels...)</p>\n'}, {'answer_id': 50729, 'author': 'OwenP', 'author_id': 2547, 'author_profile': 'https://Stackoverflow.com/users/2547', 'pm_score': 5, 'selected': True, 'text': "<p>Learn how the <em>Anchor</em> and <em>Dock</em> properties work on your controls, leave anything that can <em>AutoSize</em> itself alone, and use a <code>TableLayoutPanel</code> when you can.</p>\n\n<p>If you do these three things, you'll get a lot of the WPF design experience in Windows Forms.  A well-designed <code>TableLayoutPanel</code> will do its best to size the controls so that they fit the form properly.  Combined with <em>AutoSize</em> controls, docking, and the <em>AutoScaleMode</em> mentioned by Soeren Kuklau you should be able to make something that scales well.  If not, your form might just have too many controls on it; consider splitting it into tab pages, floating toolboxes, or some other space.</p>\n\n<p>In WPF it's a lot easier because the concept of auto-sizing controls is built-in; in most cases if you are placing a WPF element by using a coordinate pair you are doing it wrong.  Still, you can't change the fact that at lower resolutions it doesn't take much 120 dpi text to fill up the screen.  Sometimes the problem is not your layout, but an attempt to put too much into a small space.</p>\n"}]
['https://Stackoverflow.com/questions/50528', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3191/']