Friday, May 1, 2015

DPI Awareness in WinForms

You may have heard of a thing called DPI. In a literal sense, it means "dots per inch", but in the UI world, it affects the scale of your form elements. If you design a form at a certain scaling level but it's used at a different level, there's a chance you'll get ugly overlapping UI elements.

In .NET, DPI awareness is governed by the AutoScaleMode property on container controls (things like Form or Panel). If you set that property to Font, scaling will happen relative to the font size, which is usually what you want. I'm not exactly sure what the Dpi option does (MSDN says it scales relative to the system DPI setting, which sounds nice), but I haven't tried it.

I've also heard that layout panels like TableLayoutPanel or FlowLayoutPanel help with DPI scaling issues, but I haven't made serious use of them either.

No comments:

Post a Comment