共用方式為


HtmlElementEventHandler 代理人

定義

表示將處理 ClickMouseDown,以及 HtmlDocumentHtmlElementHtmlWindow 之相關事件的方法。

public delegate void HtmlElementEventHandler(System::Object ^ sender, HtmlElementEventArgs ^ e);
public delegate void HtmlElementEventHandler(object sender, HtmlElementEventArgs e);
public delegate void HtmlElementEventHandler(object? sender, HtmlElementEventArgs e);
type HtmlElementEventHandler = delegate of obj * HtmlElementEventArgs -> unit
Public Delegate Sub HtmlElementEventHandler(sender As Object, e As HtmlElementEventArgs)

參數

sender
Object

事件的來源。

e
HtmlElementEventArgs

包含事件資料的 HtmlElementEventArgs

範例

下列程式碼會在 上 HtmlDocument 附加 、 MouseMoveMouseUp 事件的事件處理常式 MouseDown 。 此程式碼範例假設您的專案具有名為 WebBrowser1WebBrowser 控制項實例。

private:
   void webBrowser1_DocumentCompleted( Object^ /*sender*/, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^ /*e*/ )
   {
      WebBrowser1->Document->MouseDown += gcnew HtmlElementEventHandler( this, &Form1::Document_MouseDown );
      WebBrowser1->Document->MouseMove += gcnew HtmlElementEventHandler( this, &Form1::Document_MouseMove );
      WebBrowser1->Document->MouseUp += gcnew HtmlElementEventHandler( this, &Form1::Document_MouseUp );
   }

   void Document_MouseDown( Object^ /*sender*/, HtmlElementEventArgs^ /*e*/ )
   {
      // Insert your code here.
   }

   void Document_MouseMove( Object^ /*sender*/, HtmlElementEventArgs^ /*e*/ )
   {
      // Insert your code here.
   }

   void Document_MouseUp( Object^ /*sender*/, HtmlElementEventArgs^ /*e*/ )
   {
      // Insert your code here.
   }
private void webBrowser1_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
    WebBrowser1.Document.MouseDown += new HtmlElementEventHandler(Document_MouseDown);
    WebBrowser1.Document.MouseMove += new HtmlElementEventHandler(Document_MouseMove);
    WebBrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);
}

private void Document_MouseDown(object sender, HtmlElementEventArgs e)
{
    // Insert your code here.
}

private void Document_MouseMove(object sender, HtmlElementEventArgs e)
{
    // Insert your code here.
}

private void Document_MouseUp(object sender, HtmlElementEventArgs e)
{
    // Insert your code here.
}
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    Dim Doc As HtmlDocument = WebBrowser1.Document

    AddHandler Doc.MouseDown, New HtmlElementEventHandler(AddressOf Document_MouseDown)
    AddHandler Doc.MouseMove, New HtmlElementEventHandler(AddressOf Document_MouseMove)
    AddHandler Doc.MouseUp, New HtmlElementEventHandler(AddressOf Document_MouseUp)
End Sub

Private Sub Document_MouseDown(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
    ' Insert your code here.
End Sub

Private Sub Document_MouseMove(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
    ' Insert your code here.
End Sub

Private Sub Document_MouseUp(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
    ' Insert your code here.
End Sub

備註

建立 HtmlElementEventHandler 委派時,必須識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需事件處理常式委派的詳細資訊,請參閱 處理和引發事件

您必須等到 HTML 檔案完成載入,才能將事件處理常式附加至檔。 如果您在載入完成之前嘗試附加處理常式,附加作業可能會失敗。 新檔中附加事件處理常式的最佳位置是在 DocumentCompleted 控制項的事件處理常式中 WebBrowser

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於