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

前端 未结 4 745
粉色の甜心
粉色の甜心 2021-02-10 00:32

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

相关标签:
4条回答
  • 2021-02-10 01:00

    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.

    0 讨论(0)
  • 2021-02-10 01:05

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

    0 讨论(0)
  • 2021-02-10 01:14

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

    0 讨论(0)
  • 2021-02-10 01:21

    The short answer is yes.

    See this article on codeproject.

    Here is another (shorter) article on codeproject

    0 讨论(0)
提交回复
热议问题