在 Office Add-in C# 中,是否有仅在 Office 应用程序顶部打开表单的选项? [英] In Office Add-in C#, There is an option to open Form on top of the office Application only?

查看:67
本文介绍了在 Office Add-in C# 中,是否有仅在 Office 应用程序顶部打开表单的选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TopMost 它不好,因为它位于计算机中的所有应用程序之上.除了 ShowDialog() 方式,因为它锁定了应用程序.

TopMost it's not good because it's on top of all the applications in the computer. Except ShowDialog() way, because it's lock the Application.

推荐答案

您需要使用无模式对话框,以免阻塞主办公室应用程序.您还需要将 Office 应用程序设置为无模式对话框的父窗口.

You need to use a modaless dialog in order not to block the Main Office application. You also need to set the Office Application as parent window of the modaless dialog.

1) 使用此答案中的 WindowWrapper 类.

1) Use the WindowWrapper class from this answer.

2) 假设您有权访问 Office 应用程序的 Application 对象.App.WindowHandle32 是主窗口.

2) Lets assume you have the access to Application object of your Office app. App.WindowHandle32 is the handle to the main Window.

3) 代码:

        var someDialog = new Form1();
        someDialog.Show(new WindowWrapper(new IntPtr(App.WindowHandle32)));

4) 记得将 someDialog 变量声明为类成员.

4) Remember to declare the someDialog variable as a class member.

这篇关于在 Office Add-in C# 中,是否有仅在 Office 应用程序顶部打开表单的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆