我的WinForms浏览器控件有3个上下文菜单。
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将很容易重写。
由于