【发布时间】:2012-06-07 18:53:59
【问题描述】:
如何禁用 WPF WebBrowser-Control 的标准上下文菜单?
【问题讨论】:
-
好问题,+1up。这可能会有所帮助stackoverflow.com/questions/5507734/…
标签: c# .net wpf webbrowser-control
如何禁用 WPF WebBrowser-Control 的标准上下文菜单?
【问题讨论】:
标签: c# .net wpf webbrowser-control
使用 mshtml;
private mshtml.HTMLDocumentEvents2_Event documentEvents;
在构造函数或 xaml 中设置您的 LoadComplete 事件:
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
}
【讨论】: