Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Windows. Forms;
Using System. Threading;
Using HtmlDom;
Namespace HTMLElementSelect
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
AboutForm afrm = new AboutForm ();
Private void Form1_Load (object sender, EventArgs e)
{
WebBrowser1.Navigate ("http://www.cnblogs.com/JiangHuakey ");
WebBrowser1.ContextMenuStrip = contextMenuStrip1 ;//! Set our own pop-up menu
WebBrowser1.IsWebBrowserContextMenuEnabled = false ;//! Disable the default pop-up menu of IE
}
Private void contextmenustripappsopening (object sender, CancelEventArgs e)
{
//! Screen coordinates
Point ScreenCoord = new Point (MousePosition. X, MousePosition. Y );
//! Browser coordinates
Point BrowserCoord = webBrowser1.PointToClient (ScreenCoord );
HtmlElement elem = webBrowser1.Document. GetElementFromPoint (BrowserCoord );
//! Hide all menu items
For (int I = 0; I <contextMenuStrip1.Items. Count; I ++)
{
ContextMenuStrip1.Items [I]. Visible = false;
}
//! Display the corresponding menu
Switch (elem. TagName)
{
Case "":
//! For a hyperlink, the relevant hyperlink menu items are displayed.
OpenToolStripMenuItem. Visible = true;
OpenInNewTabToolStripMenuItem. Visible = true;
OpenInNewWindowToolStripMenuItem. Visible = true;
Break;
Case "IMG ":
//! If it is an image, the corresponding menu items are displayed.
SaveImageToolStripMenuItem. Visible = true;
SetAsDesktopWallpaperToolStripMenuItem. Visible = true;
Break;
Default:
//! Others
RefreshToolStripMenuItem. Visible = true;
ViewSourceToolStripMenuItem. Visible = true;
Break;
}
}
Void SaveImageToolStripMenuItemClick (object sender, EventArgs e)
{
Afrm. Show ();
}
Void SetAsDesktopWallpaperToolStripMenuItemClick (object sender, EventArgs e)
{
Afrm. Show ();
}
Void OpenToolStripMenuItemClick (object sender, EventArgs e)
{
Afrm. Show ();
}
Void OpenInNewTabToolStripMenuItemClick (object sender, EventArgs e)
{
Afrm. Show ();
}
Void OpenInNewWindowToolStripMenuItemClick (object sender, EventArgs e)
{
Afrm. Show ();
}
Void RefreshToolStripMenuItemClick (object sender, EventArgs e)
{
Afrm. Show ();
}
Void ViewSourceToolStripMenuItemClick (object sender, EventArgs e)
{
Afrm. Show ();
}
}
}