HtmlDocument.ContextMenuShowing 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當使用者請求顯示文件的右鍵選單時,會發生這種情況。
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
事件類型
範例
以下程式碼範例捕捉事件 ContextMenuShowing 並用來顯示一個 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;
}
備註
預設情況下,如果你在文件或文件中的元素上右鍵點擊滑鼠,會顯示該元素專屬的預設右鍵選單。 利用此事件取消右鍵選單的顯示,改為顯示你自己的選單。