在 WPF 中禁用 Web 浏览器上的上下文菜单
我有一个WPF应用程序,该应用程序将在带触摸屏的PC上运行的售货亭。该应用以全屏模式运行,以隐藏OS。在我的一个页面上,我有一个WebBrowser控件,该控件允许用户查看某些网页(导航仅限于某些页面)。 由于计算机将放置在公共位置,因此我不得让用户访问操作系统。问题是,触摸屏允许右键单击网络浏览器,最终导致任务栏出现...不好..!
我一直在尝试在过去几天禁用上下文菜单,但没有成功。基本上我现在处于的位置是:
添加了com引用到shdocvw.dll以获取iwebbrowser2接口(需要禁用新窗口的启动。
[comimport,InterfaceType(cominterfacetype.interfaceisiunknown)]] [GUID(“ 6D5140C1-7436-11CE-8034-00AA006009FA”)]] 内部接口IserviceProvider { [返回:MARSHALAS(UNMANAGGEDTYPE.IUNKNOWN)] 对象QueryService(Ref GuidService,Ref Guid Riid); } 静态只读 Guid SID_SWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
获取iwebbrowser2接口
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。
htmldocument doc = _webbrowser.document as htmldocument; mshtml.htmldocumentEvents2_event ev = doc as Mshtml.htmldocumentEvents2_event; ev.oncontextmenu +=(arg)=> {返回false; };
到目前为止,没有成功...有什么想法吗?
提前致谢。
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:
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");
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);
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; };
So far, no sucess... any ideas?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 oncontextmenu 属性添加到文档正文标记对我有用。
从这篇文章这里。
http://social.msdn.microsoft.com /forums/zh-CN/wpf/thread/7c283faf-16c8-4b4e-a362-f292e3032abb/
Adding an oncontextmenu attribute to the document body tag worked for me.
From this article here.
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7c283faf-16c8-4b4e-a362-f292e3032abb/
为什么不使用 WPF WebBrowser 控件?它有许多触摸事件,您可以捕获和处理这些事件,并有可能阻止上下文菜单弹出。或者您可以提供自己的上下文菜单供浏览器使用。
预览事件位于页面下方,可用于拦截导致弹出上下文菜单的事件。
OnPreviewTouchDown
OnPreviewTouchMove
OnPreviewTouchUp
Why aren't you using the WPF WebBrowser control? It has many Touch events that you could capture and handle and potentially stop the ContextMenu from ever popping up. Or you could supply your own ContextMenu for the browser to use.
The preview events are lower down on the page and can be used to intercept events that would cause the context menu to pop-up.
OnPreviewTouchDown
OnPreviewTouchMove
OnPreviewTouchUp