I'm working on an Excel add-in and I have a form (WinForms) that I would like to be modal, and show center parent. I'm assigning the Excel's handle to a NativeWindow
, and then using that as the owner
argument when I call ShowDialog
. Looks something like this:
NativeWindow excel = new NativeWindow();
excel.AssignHandle(new IntPtr(application.Hwnd)); // interop Excel app
MyWindow window = new Window();
window.ShowDialog(excel);
The call to ShowDialog
here takes ~5 seconds. If I simply call ShowDialog
normally, all the other code intact, it comes up immediately — so I'm reasonably confident that's the culprit.
Am I doing something stupid here? Are there events or lazy loading going on under the hood (or with Excel itself) that I could kick off earlier?