C# 如何在互操作期间停止弹出 MS Graph 组件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-01 09:04:10  来源:igfitidea点击:

How do I stop MS Graph component popping up during Interop?

提问by jmcd

When using Office Interop in C#, if you insert a chart object into a MS Word document, the Grap application loads up very briefly and then goes away. Is there a way to prevent this from happening? I have tried setting the Visible property of the application instance to false to no effect.

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

EDIT: The Visible property does take effect when used against Word when interopping, and it does notpop up. I would expect there is a similar way to do this for MS Graph.

编辑: Visible 属性在互操作时对 Word 使用时确实生效,并且不会弹出。我希望有一种类似的方法可以为 MS Graph 执行此操作。

回答by Coincoin

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 usuallyrecycle an existing process, hopefuly the one with the hidden main window.

我过去尝试过的一个 hack(对于完全不相关的东西)是启动一个进程并不断检测它的主窗口是否被创建。一旦它被创建,我就隐藏了它。您可以使用故障应用程序的主模块执行此操作,并希望它能够足够快地在用户注意到之前隐藏窗口。然后你实例化你的组件;该组件通常会回收现有进程,希望隐藏主窗口的进程。

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.

我不能保证这在你的情况下会起作用,但值得一试,这个问题很重要,或者如果你当然没有找到更好的方法。