Is there any way to change the Context Menu of a Web browser using Wpf (C#)

Deadly 提交于 2019-12-04 14:16:07

问题


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?


回答1:


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




回答2:


The short answer is yes.

See this article on codeproject.

Here is another (shorter) article on codeproject




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/238768/is-there-any-way-to-change-the-context-menu-of-a-web-browser-using-wpf-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!