Is there any way to change the Context Menu of a W

2019-03-21 03:20发布

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?

4条回答
别忘想泡老子
2楼-- · 2019-03-21 03:35

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.

查看更多
Ridiculous、
3楼-- · 2019-03-21 03:40

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..

查看更多
仙女界的扛把子
4楼-- · 2019-03-21 03:55

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

查看更多
登录 后发表回答