DPI scaling issue with Word Task Pane

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

DPI scaling issue with Word Task Pane
Controls in the task pane are too small on high-dpi screen 
Simon Fisher




Posts: 17
Joined: 2016-07-12
We've built a Word plugin that uses custom Task Panes which contain various types of WinForms controls. We were having issues related to multiple screens, high-dpi screens etc but recent Add-In Express updates, alongside changes of our own, have helped to remedy them. However we've noticed an issue that I can't figure out how to fix and I'd appreciate some help.

I'm running a MS Surface Laptop which by default runs at 200% scaling (3000x2000). I usually have external monitors which run at 100% scaling (1920x1080 for example). For our Task Pane, we have hooked into the ADXDPIChanged event, and we are manually scaling our controls as required. We've also set the scaling mode on our user controls appropriately.

When I run our plugin with the external monitors attached, the ADXDPIChanged event fires, and all is well - our task pane adjusts regardless of whether it is displayed on the Surface laptop at 200% or one of the external monitors at 100%.

However, if I disconnect the external monitors completely, when I open Word on my laptop, the ADXDPIChanged never seems to fire, and so our custom scaling never runs. As a result, all of our dynamically created controls are half-size compared to what they should be. The Task Pane itself is the right width.

So the problem is that I can't get our task pane to scale appropriately when the primary monitor has a scale factor that is not 100%, and there are no other monitors attached.

Is there a way to ensure that the ADXDPIChanged is fired in this scenario, or is there another recommended way of detecting the current scale factor when the task pane is shown?

I'm running Add-In Express 9.2.4635, Windows 10, Office Professional Plus 2016 (v 1812, build 11126.20266 Click-to-Run). I also have 'Optimize for Compatibility' selected in Word options.

Thanks,

Simon
Posted 31 Jan, 2019 21:31:14 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Simon,

We've fixed this issue in an internal build. In a couple of minutes I'll send you a download link by email. Please let me know if it foxes the issue for you.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Feb, 2019 10:30:43 Top
Simon Fisher




Posts: 17
Joined: 2016-07-12
Hi Andrei,

Unfortunately the build that you sent me has not fixed the issue. v9.2.4636 (the build you sent) seems to have the same behaviour as v9.2.4635 - the ADXDPIChanged event is never invoked in our task pane, if I run Word on my laptop with no additional monitors attached.

Regards,

Simon
Posted 03 Feb, 2019 20:09:03 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Simon,

Please make sure that your project references the new version of AddinExpress.OL.2005.dll.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Feb, 2019 03:56:31 Top
Simon Fisher




Posts: 17
Joined: 2016-07-12
Hi Andrei,

If I look in Visual Studio, it appears that I'm referencing the correct version.

User added an image

If I check the .csproj file, I see this:


    <Reference Include="AddinExpress.OL.2005, Version=8.7.4430.2005, Culture=neutral, PublicKeyToken=e69a7e0f3592d2b8, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <Private>False</Private>
    </Reference>
    <Reference Include="AddinExpress.WD.2005, Version=8.7.4430.2005, Culture=neutral, PublicKeyToken=e69a7e0f3592d2b8, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <Private>False</Private>
    </Reference>


I assume that Visual Studio is looking in the GAC, and finding the latest version. If I use gacutil then it lists 9.2.4636.0.

Do you think I should modify the csproj so that it directly references the files in "C:\Program Files (x86)\Add-in Express\Add-in Express for .NET\Bin" ?

Also, the reference has 'Copy Local' set to False, and that DLL does not show up in the /bin folder when I build my addin - is that to be expected?

Simon
Posted 04 Feb, 2019 15:13:12 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Simon,

Simon Fisher writes:
Do you think I should modify the csproj so that it directly references the files in "C:\Program Files (x86)\Add-in Express\Add-in Express for .NET\Bin" ?


I assume you look in a different configuration of your project or in a different project.

I suggest that you unregister your project and uninstall your add-in (if it is installed). Then start the host application to make sure the add-in is missing in the host application's UI. Close the host application and register the project.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Feb, 2019 04:00:00 Top
Simon Fisher




Posts: 17
Joined: 2016-07-12
Hi Andrei,

I'm not sure what you mean with regards to the different configuration/project sorry. We do have multiple projects in our solution, the Add-In project plus some class libraries. There are no other add-ins or 'executable' projects, and the only project with any add-in express references or code is our main project.

I followed your instructions but it didn't help unfortunately. I unregistered, opened Word to confirm that our add-in was missing (it was), then registered and tried again. The result was the same.

I also built a test project to try and demonstrate the issue but I'm even more confused after the attempt. I'll zip up my source and email it to you, but a few key points:
- I'm targeting MS Office 2003 as the minimum version
- I'm only targeting MS Word (no other applications)
- The project that was created did not have any references to AddInExpress.OL.2005.dll. It only has references to MSO.2005 and WD.2005. I assume OL is for Outlook? If that's true then I've no idea why my main project has a reference to that DLL as we don't integrate with Outlook in any way (only Word).
- My test project has an advanced task pane with a few labels, and an ADXDPIChanged event handler that updates the labels with the current DPI scale factor
- In all of my tests (with external monitors attached, without, etc), that event is *never* fired. So somehow I've gone backwards

Please take a look at the example project I've sent you and let me know if I'm doing anything wrong.

Thanks,

Simon
Posted 06 Feb, 2019 15:56:58 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Simon,

I have consulted our developers and they explained that the ADXDPIChanged event occurs in two scenarios: 1) when the Office window is created on a monitor the DPI of which is different from the DPI of the main monitor in the system, and 2) when you move the Office window to a monitor with a different DPI.

According to your description, one of the external monitors was set as the main one. This explains why you get the ADXDPIChanged event. When you start without external monitors, your notebook's monitor is the main one. This is why you don't get the event in this case. You should scale the controls using the methods that you used before Microsoft introduced support for multi-DPI configurations; say, you can set AutoScaleMode=DPI on your form.


Andrei Smolin
Add-in Express Team Leader
Posted 13 Feb, 2019 06:45:43 Top
Simon Fisher




Posts: 17
Joined: 2016-07-12
Hi Andrei,

That explanation makes sense, thanks. We're already scaling things as best we can via the built in features, but we're not doing it well for controls that are created/added at runtime, where we currently need to set width/height/margin etc. We were relying on the ADXDPIChanged event to tell us what the scaling factor should be, and then we adjusted our dynamic controls accordingly.

Is there any way to determine what the current scaling factor is without the ADXDPIChanged event?
Posted 13 Feb, 2019 15:25:18 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Simon,

If you use AutoScalMode == DPI, you shouldn't use any DPI factor. Instead, you create controls sized according to the *design-time* size of your form; the form will adjust the controls in accordance with the current DPI.


Andrei Smolin
Add-in Express Team Leader
Posted 14 Feb, 2019 03:33:13 Top