0

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?

Richard Pianka
  • 3,317
  • 2
  • 28
  • 36
  • 1
    There is no obvious reason why this would be slow, beyond Excel thinking about it for a while. ShowDialog() is already pretty good at picking the right window as the owner automatically, it uses GetActiveWindow(). – Hans Passant Apr 22 '13 at 14:59
  • See http://stackoverflow.com/a/8098961/880990 for a possible solution. – Olivier Jacot-Descombes Aug 16 '13 at 15:26

0 Answers0