How to deactivate “right click” on WPF Webbrowser Control?

后端 未结 5 602
终归单人心
终归单人心 2020-12-01 09:41

I can\'t seem to find an answer to this. Does anyone know?

Thanks

5条回答
  •  星月不相逢
    2020-12-01 10:10

    This is an old question, but I had a unique problem in that I wanted/needed to use the newer CSProj file format with the .Net Core SDK but it has a known issue with not being able to reference extension libraries, such as mshtml. So I finally found a solution that's possible without a reference to mshtml.

    Some inspiration came from https://stackoverflow.com/a/28464764/2646868 where the user cast the WebBrowser.Document property to dynamic.

    Assuming webView is the name of your WebBrowser control, hook up the LoadCompleted event like such:

    private void webView_LoadCompleted(object sender, NavigationEventArgs e)
    {
        dynamic document = webView.Document;
        document.oncontextmenu += new Func(() => false);
    }
    

提交回复
热议问题