0

在 C# 中使用 Office 互操作时,如果将图表对象插入 MS Word 文档,Grap 应用程序会在很短的时间内加载然后消失。有没有办法防止这种情况发生?我尝试将应用程序实例的 Visible 属性设置为 false 无效。

编辑: Visible 属性在互操作时对 Word 使用时会生效,并且不会弹出。我希望 MS Graph 有类似的方法可以做到这一点。

4

1 回答 1

1

This is common behaviour for a lot of component hosted in an executable binary. The host application will startup and then do the job. I don't know if there is a surefire way to prevent that since you have no control over the component nor over the process until the application is started and is responding.

A hack I tried in the past (for something totally unrelated) was starting a process and constantly detecting if its main windows was created. As soon as it was created, I was hiding it. You could do this with the main module of the faulty application and hope it will be fast enough to hide the window before the user notices. Then you instanciate your component; the component will usually recycle an existing process, hopefuly the one with the hidden main window.

I can't garentee you this will work in your situation, but it's worth a try it the issue is that important, or if you don't find a better way of course.

于 2008-08-21T13:58:47.723 回答