以编程方式显示的 Word 对话框不响应鼠标单击

发布于 2024-07-11 23:25:35 字数 478 浏览 4 评论 0原文

下面的代码显示了一个插入表格对话框:

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

问题是该对话框不响应鼠标点击。 不过,它响应键盘输入。
此外,如果我按 Alt+Tab(切换到其他正在运行的应用程序),然后再次按 Alt+Tab(切换回我的应用程序),它会响应鼠标和键盘输入。

我的猜测是,我的应用程序不“知道”显示了对话框(因为它不会以常规 Form.ShownDialog 方式发生),并且它会保持焦点。

我怎么解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2024-07-18 23:25:35

我解决了。

我不太清楚为什么,但这有帮助:显示对话框之前我禁用主申请表,然后之后显示对话框我启用它。

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();
}

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文