ShowDialog() Results in Empty Form

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

ShowDialog() Results in Empty Form
A modal dialog doesn't contain any child controls when Word is configured with Optimize for best appearance 
@sp@rr0whawk




Posts: 3
Joined: 2018-06-03
We are seeing an issue with Add-In-Express and Word when the User Interface options is configured with Optimize for best appearance setting.

Our Add-In shows a modal dialog, a .NET Form, to capture some user settings. This dialog is shown when the user selects a button on the ribbon control of Word.

The problem we are seeing is that the modal dialog is not drawn correctly and is not responding to mouse or keyboard events. The dialog contains a mixture of labels, check boxes and text boxes with an OK and Cancel button. When the dialog is shown only the two button controls appear, but they don't respond to click events. The Form window can be moved around. However clicking on the close, X, button has no effect. Neither does pressing Escape.

The code is being compiled with Visual Studio 2017 (15.7.3) and the form's AutoScaleMode is set to Dpi in the designer.

If Word is set to Optimize for compatibility then the dialog appears correctly and the controls respond to mouse and keyboard events.

Word is version 2016 16.0.9330.2073 32 bit and Add-In-Express is 9.0.4610.0

The O/S is Windows 10 Version 1803 and is running with a single display at 1920 x 1080 resolution.

Excel doesn't have this display option, PowerPoint does and so we see the same problem when Optimize for best appearance is set.

Do you have any ideas as to the cause and a solution?

Many thanks.
Posted 03 Jun, 2018 15:08:26 Top
Andrei Smolin


Add-in Express team


Posts: 16209
Joined: 2006-05-11
Hello,

This issue doesn't relate to using Add-in Express; it is caused by Office supporting multiple monitors with different DPIs.

I expect that standard controls (specifically, System.Windows.Forms.CheckBox) could cause visual artifacts while the effects you describe may mean that the controls you use are non-standard controls that don't comply with what Microsoft describes at https://msdn.microsoft.com/en-us/library/windows/desktop/mt843498(v=vs.85).aspx. Am I right about your using non-standard controls? If so, I suggest that you contact the vendor. If not, you should follow that article (and sub-sections)and use the API in your implementation.

I'm sorry that the above suggests solutions that are mostly outside of your control. Alas, there's nothing I can suggest: Microsoft actually declares Windows Forms (and WPF) outdated and they seemingly do this in favor of Universal Windows Platform (UWP). I've tried to reference a UWP class library (it shows a UWP dialog) from an add-in project but this isn't supported by MS. Probably, this situation will change in the future.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 04 Jun, 2018 06:29:33 Top
@sp@rr0whawk




Posts: 3
Joined: 2018-06-03
Thank you for you response. I would like to state that there are no custom controls being used, only the standard WinForms controls provided as part of the .NET framework.

There is a Form which contains a single TabControl that is docked fill with a panel docked bottom containing two buttons. Each of the two tabs contains a single UserControl that contains a mixture of group boxes, labels, text boxes and buttons.

I have set the AutoScaleMode on the Form to both Dpi and Font to no avail. Word continues to not render anything other than the two buttons below the TabControl. The UserControl instances are set to have their AutoScaleMode property to Inherit.

One thing I forgot to mention is we are currently targeting .NET framework 4.5.2.
Posted 04 Jun, 2018 12:05:38 Top
Andrei Smolin


Add-in Express team


Posts: 16209
Joined: 2006-05-11
Hello,

If you are unable to customize your controls in order to implement support for multiple DPIs, then, until Microsoft changes something to provide such support (assuming that they will do something), we suggest that you show your dialog form bitmap-scaled. To do this, you need to call SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_SYSTEM_AWARE) immediately before you show your form. This should be enough. A more complete version of this includes getting the current context via GetThreadDpiAwarenessContext() before you change the context and restoring the context as soon as your dialog form is closed.

See also these pages:
- https://msdn.microsoft.com/en-us/library/windows/desktop/mt748629(v=vs.85).aspx
- https://msdn.microsoft.com/en-us/library/windows/desktop/mt748626(v=vs.85).aspx
- https://msdn.microsoft.com/library/windows/desktop/mt791579(v=vs.85).aspx

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 05 Jun, 2018 08:00:17 Top
@sp@rr0whawk




Posts: 3
Joined: 2018-06-03
Thank your for your suggestion. I have not tried what you suggested yet, but I thought you would like to know what I have found.

I used Spy++ on the Form modal dialog and when Word is set to Optimize for best appearance then the TabControl does not appear in the tree. I can find and see the Form window and two button child controls. The TabControl is completely missing. So it is not that it is off the screen or in a hidden state.

Switching Word back to Optomize for compatibility and locating the modal dialog again in Spy++ I can see the TabControl and its children

What is peculiar is that Add-In has a side bar window that also contains a TabControl which appears without any issue for both multiple display settings.
Posted 08 Jun, 2018 08:54:55 Top
Andrei Smolin


Add-in Express team


Posts: 16209
Joined: 2006-05-11
Thank you for posting your findings here! What you see is clearly the result of using Optimize for best appearance.

@sp@rr0whawk writes:
What is peculiar is that Add-In has a side bar window that also contains a TabControl which appears without any issue for both multiple display settings.


Side bar window? Could you please send a sample project reproducing this behavior to the support email address?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 Jun, 2018 03:30:32 Top
tttmack




Posts: 10
Joined: 2015-02-17
I had a similar issue with an Excel Add-in and some third-party controls (Syncfusion) not displaying. The problem seemed to be resolved by updating to Windows 10 build 1803 (no Excel, AddInExpress, or Syncfusion update was required). So it looks like it was an OS bug in Windows 10 build 1709 and older.
Posted 06 Jul, 2018 20:32:09 Top