0
A
回答
1
是的。
您可以參考下面的代碼。
//this code assumes WebBrowser object(_webBrowser) is already initiated
//in class scope.
//this method is needed to execute when form is loaded.
//Register it to load event
private void Loaded(object sender, RoutedEventArgs e)
{
_webBrowser.LoadCompleted += _webBrowser_LoadCompleted;
}
private HTMLDocumentEvents2_Event _docEvent;
private void _webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
if (_docEvent != null)
{
_docEvent.oncontextmenu -= new HTMLDocumentEvents2_oncontextmenuEventHandler(_docEvent_oncontextmenu);
}
if (_webBrowser.Document != null)
{
_docEvent = (HTMLDocumentEvents2_Event)_webBrowser.Document;
_docEvent.oncontextmenu += new HTMLDocumentEvents2_oncontextmenuEventHandler(_docEvent_oncontextmenu);
}
}
bool _docEvent_oncontextmenu(IHTMLEventObj pEvtObj)
{
//do something and determine you want whether context menu shows or not
//if you want to shows context menu, you'll need to return true.
return true;
}
1
如果你想顯示自己的contextMenu代替。我這裏貼的解決方案,對於一個WinForms WebBrowser控件的工作原理:
How do you override the ContextMenu that appears when right clicking on winforms WebBrowser Control?
相關問題
- 1. WebBrowser控件不活動
- 2. 在WebBrowser控件中獲取活動網站的標題
- 3. WindowForms中的.NET WebBrowser控件
- 4. .NET WebBrowser控件和刷新
- 5. .net WebBrowser控件修改html?
- 6. 獲取.NET精簡框架使用WebBrowser控件的網頁
- 7. 如何從.NET中的WebBrowser控件獲取響應頭?
- 8. 處理.net WebBrowser控件
- 9. 替代WebBrowser控件.Net C#?
- 10. 華廷與.NET WebBrowser控件
- 11. 禁用WebBrowser contextmenu
- 12. 如何從.NET WebBrowser控件獲取反饋/交互?
- 13. 如何獲取WebBrowser控件的URL
- 14. .NET WebBrowser控件捕捉下載
- 15. 獲取javascript變量到webbrowser控件winforms
- 16. WebBrowser控件 - 獲取元素按類型?
- 17. WebBrowser控件獲取表單操作
- 18. 從WebBrowser控件獲取所有文本
- 19. 在WebBrowser控件中獲取Silverlight Canvas
- 20. .NET WebBrowser控件的替代品?
- 21. .NET按名稱動態獲取控件
- 22. .Net使用IE10的WebBrowser控件
- 23. .NET WebBrowser控件中的HtmlDocument.InvokeScript問題
- 24. 活動組中的Contextmenu
- 25. 如何獲取WebBrowser控件中的所有頁面的位圖使用.NET CF
- 26. WebBrowser控件ScreenShot
- 27. 如何獲得當前裝入WebBrowser控件.NET中的圖像
- 28. VC++ WebBrowser控件.Net依賴關係
- 29. WebBrowser控件問題
- 30. 如何獲取C#WebBrowser控件以顯示jpeg文件(原始)?
錯誤的位置:docEvent =(HTMLDocumentEvents2_Event)_webBrowser.Document; 無法將類型'System.Windows.Forms.HtmlDocument'轉換爲'mshtml.HTMLDocumentEvents2_Event – TreantBG 2011-06-16 16:15:10
糟糕!對不起,煩人。我提到了WPF WebBrowser。在Winform WebBrowser,你可以使用_webBrowser.Document.DomDocument。 – 2011-06-16 16:38:26
您需要在WPF的LoadCompleted事件的WinForm intead中使用DocumentCompleted事件。 – 2011-06-16 16:47:46