0

We are in the process of making our Winforms based application DPI aware(Per monitor), where the UI layer has several custom WinForms controls with custom drawing which is pixel based.

I am looking for some samples demonstrating what exactly the developers need to do for custom controls to appear scaled on High DPI monitors. Winforms is pixel based, but, as far as I understand the hard coded pixel based constants used in the custom drawing logic have to be dpi scaled. It would be good if the sample shows how to use Winforms automatic scaling framework to scale custom controls.(I would like to use AutoScaleMode.Dpi)

Some sample code which I could find online are confusing.

  • The WinForms' scaling logic should be taking care of scaling the basic dimensions of controls(size, height, width etc.). Is there a need to scale those aspects for custom controls?
  • Is setting control.AutoSize= true a must for control scaling to apply?
  • What should we do for icons? Scale them or choose based on DPI?
Twinkle
  • 11
  • 2
  • *provide High DPI support* is vague. What kind of support? Is your Application already DPIAware? What kind of DPI Awareness? Do you need to scale your Forms, so they occupy the same relative size in different screens? Are you using TableLayoutPanels, for example, specifying relative dimensions for Columns/Rows? When drawing, do you consider *pixel positions* or you draw using size of the *canvas* as reference? -- `.AutoSize` has a different logic applied on a Control type basis (it means something for a Label, something else for a TextBox etc.). This question is very broad. – Jimi Nov 05 '19 at 07:49
  • 2
    I'ld start from here: [High DPI support in Windows Forms](https://learn.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms), [High DPI Desktop Application Development on Windows](https://learn.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows), [How can I update my WinForms app to behave better at high DPI, or at normal DPI on very large screens?](https://devblogs.microsoft.com/oldnewthing/?p=93695), [These guidelines may help](https://stackoverflow.com/q/22735174/7444103) (though not all applies as described) – Jimi Nov 05 '19 at 07:56
  • Thanks for sharing the links. Do you have some links to samples for HighDPI related samples showing how to handle DPI based scaling for custom controls? What is the relation between AutoSize and HighDPI scaling? – Twinkle Nov 06 '19 at 16:27

0 Answers0