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

发布于 2024-07-07 04:57:23 字数 106 浏览 6 评论 0原文

我想更改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半﹌身腐败 2024-07-14 04:57:23

回答 - 是的。
网络浏览器控件中有一个设置:
.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..

瞄了个咪的 2024-07-14 04:57:23

最简洁的答案是不。 请参阅此帖子 了解更多详情。

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

七分※倦醒 2024-07-14 04:57:23

我正在尝试做同样的事情。 我读了大约 5 篇代码项目文章(顺便说一句,它们有点旧),但无法正确理解 COM 互操作部分。 可能是因为我不会用C++编程。

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

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

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

并粘贴接口定义的代码。 然后让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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文