在web浏览器中的WPF中禁用上下文菜单 [英] Disable Context Menu on WebBrowser in WPF

查看:231
本文介绍了在web浏览器中的WPF中禁用上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,是要在一个小亭运行,带有触摸屏的PC上。该应用程序运行在全屏模式下,隐藏的操作系统。在我的网页我有一个WebBrowser控件,它允许用户查看某些网页(导航仅限于某些页面)。 由于计算机将被放置在一个公共点我不能让用户访问操作系统。关键是,触摸屏允许使用右键点击网页浏览器,并最终导致任务栏出现......不好..!

I have a WPF App that is going to run on a kiosk, on a PC with a touchscreen. The App runs in fullscreen mode, to hide the OS. On one of my pages I have a WebBrowser control that allows a user to view some web pages (navigation is limited to some pages). Since the computer will be placed in a public spot I mustn't let the user access the operating system. The thing is, the touchscreen allows for a right click on the web browser, and that eventually leads to the task bar appearing... not good..!

我一直试图禁用对过去的日子的上下文菜单中没有取得多大成功。基本上,我在哪里,现在是:

I've been trying to disable that context menu for the past days without much success. Basically where i'm at right now is:

  • 添加一个COM引用shdocvw.dll中得到IWebBrowser2接口(需要禁用新窗口的启动。

  • Added a COM reference to SHDocVw.dll to get the IWebBrowser2 interface (needed to disable the launching of new windows.

[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("6d5140c1-7436-11ce-8034-00aa006009fa")]
internal interface IServiceProvider
{
    [return: MarshalAs(UnmanagedType.IUnknown)]
    object QueryService(ref Guid guidService, ref Guid riid);
}
static readonly Guid SID_SWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");

  • 取的IWebBrowser2接口

  • Fetch the IWEbBrowser2 interface

                IServiceProvider _serviceProvider = null;
    
                if (_browser.Document != null)
                {
                    _serviceProvider = (IServiceProvider)_browser.Document;
    
                    Guid _serviceGuid = SID_SWebBrowserApp;
                    Guid _iid = typeof(SHDocVw.IWebBrowser2).GUID;
    
                    SHDocVw.IWebBrowser2 _webBrowser = (SHDocVw.IWebBrowser2)_serviceProvider.QueryService(ref _serviceGuid, ref _iid);
    

  • 和尝试,并禁止对文档的oncontextmenu。

  • And try and disable the oncontextmenu on the document.

                    HTMLDocument doc = _webBrowser.Document as HTMLDocument;
                    mshtml.HTMLDocumentEvents2_Event ev = doc as mshtml.HTMLDocumentEvents2_Event;
    
                    ev.oncontextmenu += (arg) => { return false; };
    

  • 到目前为止,还没有sucess ...任何想法?

    So far, no sucess... any ideas?

    在此先感谢。

    推荐答案

    添加一个oncontextmenu属性添加到文档body标签为我工作。

    Adding an oncontextmenu attribute to the document body tag worked for me.

    <body oncontextmenu="return false;">
    

    从这篇文章在这里。 <一href="http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7c283faf-16c8-4b4e-a362-f292e3032abb/" rel="nofollow">http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7c283faf-16c8-4b4e-a362-f292e3032abb/

    From this article here. http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7c283faf-16c8-4b4e-a362-f292e3032abb/

    这篇关于在web浏览器中的WPF中禁用上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆