在 Office 加载项 C# 中,是否可以选择仅在 office 应用程序之上打开表单?

In Office Add-in C#, There is an option to open Form on top of the office Application only?

TopMost不好,因为它在计算机中的所有应用程序之上。 ShowDialog() 方式除外,因为它会锁定应用程序。

您需要使用无模态对话框,以免阻塞 Main Office 应用程序。 您还需要将 Office 应用程序设置为无模态对话框的父级 window。

1) 使用此答案中的 WindowWrapper class。

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

的句柄

3)代码:

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

4) 记得将 someDialog 变量声明为 class 成员。