1
我有我的WinForms浏览器控件的3个上下文菜单。WinForm浏览器控件哪个元素被右键点击?
BrowserImages,BrowserLinks和BrowserDefault。你猜 - - 映像是正确的,当文档的空白区域是正确的
- 默认加载点击。
当DocumentCompleted被激发我添加Document_ContextMenuShowing事件 - 该代码是:
/// <summary>
/// Displays the Correct Context Menu for the element that is being right clicked on
/// </summary>
/// <param name="sender">
/// HTMLDocument: The content of the web browser when the right click was detected.
/// </param>
/// <param name="e">
/// HtmlElementEventArgs: Used for getting the location of the mouse so we know where to display the Context Menu
/// </param>
void Document_ContextMenuShowing(object sender, HtmlElementEventArgs e)
{
var res = (HtmlDocument)sender;
if (res.ActiveElement.InnerHtml.ToLowerInvariant().Contains("img"))
{
cmsBrowserImages.Show(e.ClientMousePosition.X, e.ClientMousePosition.Y);
}
else if (res.ActiveElement.InnerHtml.ToLowerInvariant().Contains("href"))
{
cmsBrowserLinks.Show(e.ClientMousePosition.X, e.ClientMousePosition.Y);
}
else
{
cmsBrowserDefault.Show(e.ClientMousePosition.X, e.ClientMousePosition.Y);
}
}
是否还有更好的,更强大的(更好的工作)的方式来做到这一点? C#代码首选,但VB.Net将beok,很容易重写。
感谢