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

一个人想着一个人 提交于 2021-01-29 05:00:28

问题


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.


回答1:


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) Use the WindowWrapper class from this answer.

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

3) Code:

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

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



来源:https://stackoverflow.com/questions/61756628/in-office-add-in-c-there-is-an-option-to-open-form-on-top-of-the-office-applic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!