HtmlDocument.ContextMenuShowing Event
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when the user requests to display the document's context menu.
public:
event System::Windows::Forms::HtmlElementEventHandler ^ ContextMenuShowing;
public event System.Windows.Forms.HtmlElementEventHandler ContextMenuShowing;
public event System.Windows.Forms.HtmlElementEventHandler? ContextMenuShowing;
member this.ContextMenuShowing : System.Windows.Forms.HtmlElementEventHandler
Public Custom Event ContextMenuShowing As HtmlElementEventHandler
The following code example captures the ContextMenuShowing event and uses it to display a ContextMenuStrip.
ContextMenuStrip menuStrip = null;
public void DetectContextMenu()
{
if (webBrowser1.Document != null)
{
webBrowser1.Document.ContextMenuShowing += new HtmlElementEventHandler(Document_ContextMenuShowing);
menuStrip = new ContextMenuStrip();
menuStrip.Items.Add("&Custom menu item...");
}
}
void Document_ContextMenuShowing(object sender, HtmlElementEventArgs e)
{
menuStrip.Show(e.MousePosition);
e.ReturnValue = false;
}
By default, if you right-click your mouse on a document or an element in a document, it will display a default context menu particular to the element. Use this event to cancel the display of the context menu and display one of your own.
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: