I develop a VSTO add-in for Ms Word, which includes a WinForm UserControl
object embedded into a Microsoft.Office.Tools.CustomTaskPane
.
Development and testing are done via Visual Studio 2017, from two machines:
- A desktop on Windows 7 + "Low" DPI screen
- A laptop on Windows 10 + High DPI screen
The user control was designed from machine 1. When I open the project on machine 2, or when I compile from machine 1 and run on machine 2, I have the classic Low DPI to High DPI problems: the form layout becomes messy.
I understand the basics of DPI awareness, the various modes VS can run, and have been told that WPF handles DPI far better than WinForms.
My upmost concern is: Is there a way to design my forms from machine 1 so that they display correctly under high DPI environments? Or is it better to (re) design the forms on machine 2 ?
From this, derive other questions:
- Once I will have re-designed the forms from a high DPI environment, should I expect to run into the reverse problem? (i.e., dodgy High DPI to Low DPI conversions?)
- A
CustomTaskPane
only accepts WinFormUserControl
objects. Would I gain anything in creating a blankUserControl
in which I would embed aWPF
? - I target the .Net Framework 4.0. Would I gain anything (DPI compatibility-wise) in targeting a later version?
For those who bumped into this question because they face the same problem, some reading I found useful:
- https://learn.microsoft.com/en-us/dotnet/framework/winforms/automatic-scaling-in-windows-forms
- https://learn.microsoft.com/en-us/dotnet/framework/winforms/disable-dpi-awareness-visual-studio
- https://learn.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms
- https://learn.microsoft.com/en-us/office/client-developer/ddpi/handle-high-dpi-and-dpi-scaling-in-your-office-solution
- https://stackoverflow.com/a/52454103/10794555