禁用网络浏览器上下文菜单
本文关键字:上下文 菜单 浏览器 网络 | 更新日期: 2023-09-27 18:36:27
如何禁用 WPF WebBrowser-Control 的标准上下文菜单?
使用 mshtml;
private mshtml.HTMLDocumentEvents2_Event documentEvents;
在构造函数或 XAML 中设置加载完成事件:
webBrowser.LoadCompleted += webBrowser_LoadCompleted;
然后在该方法中创建新的 WebBrowser 文档对象并查看可用属性并创建新事件,如下所示:
private void webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
documentEvents = (HTMLDocumentEvents2_Event)webBrowserChat.Document; // this will access the events properties as needed
documentEvents.oncontextmenu += webBrowserChat_ContextMenuOpening;
}
private bool webBrowserChat_ContextMenuOpening(IHTMLEventObj pEvtObj)
{
return false; // ContextMenu wont open
// return true; ContextMenu will open
// Here you can create your custom contextmenu or whatever you want
}