有没有办法使用 Wpf (C#) 更改 Web 浏览器的上下文菜单
我想更改 Web 浏览器控件中提供的默认上下文菜单中的菜单项。 我已经尝试过:webbrowser.contextmenu = mycontextmenu。 没有改变。 有没有办法做到这一点?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
回答 - 是的。
网络浏览器控件中有一个设置:
.IsWebBrowserContextMenuEnabled = false;
将其设置为 false 会禁用 IE 上下文菜单,从而允许您设置的任何一个来统治根。 简单..
Answer - YES.
There is a setting in the webbrowser control for:
.IsWebBrowserContextMenuEnabled = false;
Setting this to false disables the IE contextmenu, allowing whichever one you set to rule the roots. Simples..
简短的回答是肯定的。
请参阅这篇关于 codeproject 的文章。
这是关于 codeproject 的另一篇(较短的)文章
The short answer is yes.
See this article on codeproject.
Here is another (shorter) article on codeproject
最简洁的答案是不。 请参阅此帖子 了解更多详情。
The short answer is no. See this thread for more details.
我正在尝试做同样的事情。 我读了大约 5 篇代码项目文章(顺便说一句,它们有点旧),但无法正确理解 COM 互操作部分。 可能是因为我不会用C++编程。
但后来我发现了这个页面 http://www.pinvoke.net/default。 aspx/Interfaces/IDocHostUIHandler.html 这看起来很有希望。 它包含 ac# 接口,声称可以提供您想要的功能。 然而,我仍然无法让它一直工作,所以如果其他人可以为这个答案做出贡献,我将不胜感激。
因为我不知道你对 c# 有多熟悉(顺便说一句,我几乎是个菜鸟),所以我将在这里发布一些额外的步骤,使用 VS2008。 将 Microsoft.mshtml 添加为项目的引用,创建一个新的 C# 界面,并在界面顶部添加额外的 3 个“using”语句。
并粘贴接口定义的代码。 然后让WebBrowser容器实现这个接口和所有方法。 这就是我到目前为止所取得的进展。 我仍在寻找一种将浏览器事件重定向到容器的方法。
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++.
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.
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.
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.