views:

1085

answers:

3

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?

A: 

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

Aaron Marten
+1  A: 

The short answer is yes.

See this article on codeproject.

Here is another (shorter) article on codeproject

batzen
That article is all WinForms. Do you have code that would work in WPF?
Joe White
It should work in WinForms and in WPF because it relies on customizing mshtml.NOTE: Added a new link to another article in my answer.
batzen
A: 

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.

facildelembrar