有没有办法使用Wpf(C#)更改Web浏览器的上下文菜单

时间:2022-09-13 08:31:45

I would to change the menuitems in the default context menu provided in the Web Browser Control. I have already tried: webbrowser.contextmenu = mycontextmenu. Nothing changed. Is there a way to do this?

我想在Web浏览器控件中提供的默认上下文菜单中更改菜单项。我已经尝试过:webbrowser.contextmenu = mycontextmenu。没有改变。有没有办法做到这一点?

4 个解决方案

#1


3  

Answer - YES. There is a setting in the webbrowser control for: .IsWebBrowserContextMenuEnabled = false;

答案 - 是的。 webbrowser控件中有一个设置:.IsWebBrowserContextMenuEnabled = false;

Setting this to false disables the IE contextmenu, allowing whichever one you set to rule the roots. Simples..

将此设置为false会禁用IE上下文菜单,允许您设置的任何一个来管理根。 Simples ..

#2


2  

The short answer is yes.

简短的回答是肯定的。

See this article on codeproject.

请参阅有关codeproject的这篇文章。

Here is another (shorter) article on codeproject

这是关于codeproject的另一篇(简短)文章

#3


1  

The short answer is no. See this thread for more details.

最简洁的答案是不。有关详细信息,请参阅此主题。

#4


1  

I'm trying to do the same thing. I read about 5 codeproject articles (they kind of old by the way) but couldn't get the COM interop part right. Probably because I can't program in C++.

我正在尝试做同样的事情。我读了大约5篇codeproject文章(顺便提一下它们有点旧)但是无法让COM互操作部分正确。可能是因为我不能用C ++编程。

But then I found this page http://www.pinvoke.net/default.aspx/Interfaces/IDocHostUIHandler.html which seems promising. It contains a c# interface that claims to provide the functionality you want. However I still couldn't make it work all the way, so I'd appreciate if somebody else could contribute to this answer.

但后来我发现这个页面http://www.pinvoke.net/default.aspx/Interfaces/IDocHostUIHandler.html看起来很有希望。它包含一个声称提供所需功能的c#接口。但是我仍然无法让它一直工作,所以如果其他人可以为这个答案做出贡献,我会很感激。

Since I don't know how much you are familiar with c# (I'm pretty much a noob by the way), I'll post some extra steps here, using VS2008. Add the Microsoft.mshtml as reference to your project, create a new c# interface, and on top of the interface add the extra 3 "using" statements.

因为我不知道你对c#有多熟悉(顺便说一下,我差不多是菜鸟),我会在这里发布一些额外的步骤,使用VS2008。添加Microsoft.mshtml作为项目的引用,创建一个新的c#接口,并在界面上添加额外的3“using”语句。

using System.Windows;
using System.Runtime.InteropServices;
using mshtml;

And paste the code of the interface definition. Then make the WebBrowser container implement this interface and all the methods. This is how far I got 'till now. I'm still looking for a way to redirect the browser events to the container.

并粘贴接口定义的代码。然后使WebBrowser容器实现此接口和所有方法。这是我到目前为止的距离。我仍在寻找一种方法将浏览器事件重定向到容器。

#1


3  

Answer - YES. There is a setting in the webbrowser control for: .IsWebBrowserContextMenuEnabled = false;

答案 - 是的。 webbrowser控件中有一个设置:.IsWebBrowserContextMenuEnabled = false;

Setting this to false disables the IE contextmenu, allowing whichever one you set to rule the roots. Simples..

将此设置为false会禁用IE上下文菜单,允许您设置的任何一个来管理根。 Simples ..

#2


2  

The short answer is yes.

简短的回答是肯定的。

See this article on codeproject.

请参阅有关codeproject的这篇文章。

Here is another (shorter) article on codeproject

这是关于codeproject的另一篇(简短)文章

#3


1  

The short answer is no. See this thread for more details.

最简洁的答案是不。有关详细信息,请参阅此主题。

#4


1  

I'm trying to do the same thing. I read about 5 codeproject articles (they kind of old by the way) but couldn't get the COM interop part right. Probably because I can't program in C++.

我正在尝试做同样的事情。我读了大约5篇codeproject文章(顺便提一下它们有点旧)但是无法让COM互操作部分正确。可能是因为我不能用C ++编程。

But then I found this page http://www.pinvoke.net/default.aspx/Interfaces/IDocHostUIHandler.html which seems promising. It contains a c# interface that claims to provide the functionality you want. However I still couldn't make it work all the way, so I'd appreciate if somebody else could contribute to this answer.

但后来我发现这个页面http://www.pinvoke.net/default.aspx/Interfaces/IDocHostUIHandler.html看起来很有希望。它包含一个声称提供所需功能的c#接口。但是我仍然无法让它一直工作,所以如果其他人可以为这个答案做出贡献,我会很感激。

Since I don't know how much you are familiar with c# (I'm pretty much a noob by the way), I'll post some extra steps here, using VS2008. Add the Microsoft.mshtml as reference to your project, create a new c# interface, and on top of the interface add the extra 3 "using" statements.

因为我不知道你对c#有多熟悉(顺便说一下,我差不多是菜鸟),我会在这里发布一些额外的步骤,使用VS2008。添加Microsoft.mshtml作为项目的引用,创建一个新的c#接口,并在界面上添加额外的3“using”语句。

using System.Windows;
using System.Runtime.InteropServices;
using mshtml;

And paste the code of the interface definition. Then make the WebBrowser container implement this interface and all the methods. This is how far I got 'till now. I'm still looking for a way to redirect the browser events to the container.

并粘贴接口定义的代码。然后使WebBrowser容器实现此接口和所有方法。这是我到目前为止的距离。我仍在寻找一种方法将浏览器事件重定向到容器。