Adding DPIAwareness in Winforms / WPF forms for Multiple and UHD Monitors

Add-in Express™ Support Service
That's what is more important than anything else

Adding DPIAwareness in Winforms / WPF forms for Multiple and UHD Monitors
 
TheNewCOMAddin Dev


Guest


Background:
We have a ADX based Outlook Addin. We use FormsManager and replace the reading pane and show a ADXForm with Winform controls like label button etc. This also contains a Webbrowser control display the same email with some extra html injections.

Problem:
Under UHD resolutions we see form distorts. The email in webbrowser component looks small (Remains the size it was at 96 DPI).

What we found:
https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/mt846517(v=vs.85)
Not sure if we are on the right track but it seems we set to see the "dpiAwareness" value in the manifest.
Looks like this will solve the issue.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
        <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
        <dpiAware>true</dpiAware>
    </windowsSettings>
</application>
</assembly>


Questions:
Sorry there are many:
1. Is this xml addition applicable to our scenario? if so.. Where exactly do we add this xml? Any way to do this programatically ?
2. Are there any differences in using WPF vs WinForm controls with respect to dpiAware / dpiAwareness ? We know that WPF controls can be added via the ElementHost control. Do WPF controls scale automatically ?
3. Will the webbrowser component also respect the dpiAwareness part or we need to zoom based on DPIRatio ?
4. Are there other ways of solving this problem which we are not looking at ?

We really have customers waiting for UHD support and hence any urgent help on this will be of great help, it would be best if a sample addin code that scales correctly on a UHD machine can be given so that we can avoid further questions.
Posted 02 May, 2020 06:06:23 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Jatin,

TheNewCOMAddin Dev writes:
1. Is this xml addition applicable to our scenario? if so.. Where exactly do we add this xml? Any way to do this programatically ?



No. That manifest applies to the whole Outlook application, not your add-in only. Antway, this won't solve the problem.

TheNewCOMAddin Dev writes:
Are there any differences in using WPF vs WinForm controls with respect to dpiAware / dpiAwareness ?


WPF scales well. You can scale the whole content at once. Windows Forms can scale, too, but this either doesn't work or it works bad if DPI is changed after the control is already created. You need to scale each control manually. Sometimes, this is impossibly to do and you have to replace the control. As you can see, WPF looks far better than Windows Forms here.

TheNewCOMAddin Dev writes:
3. Will the webbrowser component also respect the dpiAwareness part or we need to zoom based on DPIRatio ?


No, it won't. The content shown by the WebBrowser component should also be scaled using style (sort of zooming or something else).

TheNewCOMAddin Dev writes:
4. Are there other ways of solving this problem which we are not looking at ?


You need to scale the content of the ADXForm using the DPI property and BeforeDPIChanged and DPIChanged events that the form provides. Check also our blog at https://www.add-in-express.com/creating-addins-blog/2018/05/08/add-in-express-multiple-dpi-monitors/.

We don't have such a sample as it is impossible to provide a generic-case example.


Andrei Smolin
Add-in Express Team Leader
Posted 04 May, 2020 02:49:53 Top