HtmlElement.AttachEventHandler(String, EventHandler) HtmlElement.AttachEventHandler(String, EventHandler) HtmlElement.AttachEventHandler(String, EventHandler) Method


將具名事件的事件處理常式加入 HTML 文件物件模型 (DOM)。Adds an event handler for a named event on the HTML Document Object Model (DOM).

 void AttachEventHandler(System::String ^ eventName, EventHandler ^ eventHandler);
public void AttachEventHandler (string eventName, EventHandler eventHandler);
member this.AttachEventHandler : string * EventHandler -> unit


String String String

要處理的事件名稱。The name of the event you want to handle.

EventHandler EventHandler EventHandler

處理此事件的 Managed 程式碼。The managed code that handles the event.


管理文件物件模型 (DOM) 會公開僅選取的事件數目。The Managed Document Object Model (DOM) exposes only a select number of events. 其中大部分未公開的事件只會定義特定類型的項目;這類submit事件,這是只在有效FORM項目。Most of the unexposed events are only defined for specific types of elements; such as the submit event, which is valid only on FORM elements. 使用AttachEventHandler這些未公開的事件加入事件處理常式。Use AttachEventHandler to add an event handler to these unexposed events.

您不應該附加至文件或其中一個物件的事件,直到文件已完成載入。You should not attach an event to the document or one of its objects until the document has completed loading. 您應該呼叫這個方法最舊的處於DocumentCompleted事件的WebBrowser控制項。The earliest you should call this method is in the DocumentCompleted event of the WebBrowser control.

如需可用的非受控事件的詳細資訊,請參閱存取 Managed HTML 文件物件模型上的未公開成員與樣式有關介面:樣式有關IHTMLElement2IHTMLElement3IHTMLElement4For more information about the available unmanaged events, see Accessing Unexposed Members on the Managed HTML Document Object Model and the IHTMLElement interfaces: IHTMLElement, IHTMLElement2, IHTMLElement3, IHTMLElement4.