views:

320

answers:

2

The following piece of code shows an Insert table dialog:

Dialog d = WordApp.Dialogs[WdWordDialog.wdDialogTableInsertTable];
int result = d.Show(ref missing);
if (result == -1)  // if user pressed OK
{
    d.Execute();
}

The problem is that the dialog does not respond to mouse clicks. It responds to keyboard input, though.
Moreover, if I press Alt+Tab (to switch to some other running app) and then press Alt+Tab again (to switch back to my app), it responds to both mouse and keyboard input.

My guess is that my application doesn't 'know' that a dialog box was shown (because it doesn't happen in a regular Form.ShownDialog way) and it keeps the focus.

How can I solve this problem?

A: 

I cannot reproduce the problem with Word 2007.

What Office version are you using? Do you get the same behavior with all dialogs or only with the insert table dialog?

0xA3
Office 2003. The Print dialog behaves the same. Maybe the problem is caused by something happening in the code (I am maintaining an app I did not create).
Marek Grzenkowicz
A: 

I worked it out.

I'm not exactly sure why but this helps: before displaying the dialog I disable the main application form, then after the dialog is displayed I enable it back.

Dialog d = WordApp.Dialogs[WdWordDialog.wdDialogTableInsertTable];

MainApplicationFormInstance.Enabled = false;
int result = d.Display(ref missing);
MainApplicationFormInstance.Enabled = true;

if (result == -1)  // user pressed OK
{
    d.Execute();
}
Marek Grzenkowicz