Reputation: 143
I'm working in a company that has a Winforms application as our flagship product. we recently reworked the branding and UI. We have noticed that the Forms now do not display the text properly and some controls are out of alignment or have disappeared off the edge.
Is it possible for me to make the forms on this application DPI-Aware with the least amount of re-factoring as we don't have time.
Upvotes: 4
Views: 8142
Reputation: 599
It's essential that you don't specify pixel coordinates and sizes. This rules out using Control.Top
and Control.Left
, which is what the designer does, when you "just place" the controls on a form.
To get an UI that works with different DPI settings, pretty much everything has to be dynamically sized. The controls should have Control.AutoSize
enabled. But just enabling AutoSize
would totally screw up your layout, since the control position would still be static.
To get dynamically position the controls, you can use container controls, like the FlowLayoutPanel
and the TableLayoutPanel
(with sizes set to AutoSize
). The normal controls inside of those would then just move arround the form, according to automatically determined sizes.
As you can see, this isn't simple, requires a bit of experience to get it right and needs a huge amount of testing (virtual machines with different DPI settings work great). But I think it should definitely be done, since I'm always annoyed if something looks stupid and buggy on my laptop.
Upvotes: 13
Reputation: 707
The quickest way is to override OnPaint and use the Graphics.DpiX and DpiY properties. Refer to http://msdn.microsoft.com/en-us/library/ms701681(VS.85).aspx only recommendation is to use a manifest file instead of SetDpiAware
Upvotes: -3