This documentation is archived and is not being maintained.

HtmlElementEventArgs Class

Provides data for the events defined on HtmlDocument and HtmlElement.


Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public sealed class HtmlElementEventArgs : EventArgs

The HtmlElementEventArgs type exposes the following members.

Public propertyAltKeyPressedIndicates whether the ALT key was pressed when this event occurred.
Public propertyBubbleEventGets or sets a value indicating whether the current event bubbles up through the element hierarchy of the HTML Document Object Model.
Public propertyClientMousePositionGets or sets the position of the mouse cursor in the document's client area.
Public propertyCtrlKeyPressedIndicates whether the CTRL key was pressed when this event occurred.
Public propertyEventTypeGets the name of the event that was raised.
Public propertyFromElementGets the HtmlElement the mouse pointer is moving away from.
Public propertyKeyPressedCodeGets the ASCII value of the keyboard character typed in a KeyPress, KeyDown, or KeyUp event.
Public propertyMouseButtonsPressedGets the mouse button that was clicked during a MouseDown or MouseUp event.
Public propertyMousePositionGets or sets the position of the mouse cursor relative to a relatively positioned parent element.
Public propertyOffsetMousePositionGets or sets the position of the mouse cursor relative to the element that raises the event.
Public propertyReturnValueGets or sets the return value of the handled event.
Public propertyShiftKeyPressedIndicates whether the SHIFT key was pressed when this event occurred.
Public propertyToElementGets the HtmlElement toward which the user is moving the mouse pointer.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

HtmlElementEventArgs encapsulates the same information found on the window.event object when programming against the unmanaged HTML DOM or when writing Active Script for HTML pages.

In most cases, you can use ToElement to find the HTML element that is receiving the event action, and FromElement to find the HTML element that the current event is causing us to leave. However, not every event supplies a value for these properties; see the managed documentation for an event, or the corresponding documentation in the Internet Explorer SDK documentation, to discover if the event supplies it.

Many events in the HTML DOM are sent to their parent elements unless they are cancelled. This is known as event bubbling. If a SPAN inside of a DIV receives a click, then a click event is raised for the SPAN first, then for the DIV, and finally for the HTML page's BODY element. BubbleEvent controls whether an event will behave in this manner or not.

The following code example demonstrates the use of this type. In the example, an event handler reports on the occurrence of the Click event. This report helps you to learn when the event occurs and can assist you in debugging. To report on multiple events or on events that occur frequently, consider replacing Show with Console.WriteLine or appending the message to a multiline TextBox.

To run the example code, paste it into a project that contains an instance of type HtmlDocument named HtmlDocument1. Then ensure that the event handler is associated with the Click event.

private void HtmlDocument1_Click(Object sender, HtmlElementEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "MouseButtonsPressed", e.MouseButtonsPressed );
messageBoxCS.AppendFormat("{0} = {1}", "ClientMousePosition", e.ClientMousePosition );
messageBoxCS.AppendFormat("{0} = {1}", "OffsetMousePosition", e.OffsetMousePosition );
messageBoxCS.AppendFormat("{0} = {1}", "MousePosition", e.MousePosition );
messageBoxCS.AppendFormat("{0} = {1}", "BubbleEvent", e.BubbleEvent );
messageBoxCS.AppendFormat("{0} = {1}", "KeyPressedCode", e.KeyPressedCode );
messageBoxCS.AppendFormat("{0} = {1}", "AltKeyPressed", e.AltKeyPressed );
messageBoxCS.AppendFormat("{0} = {1}", "CtrlKeyPressed", e.CtrlKeyPressed );
messageBoxCS.AppendFormat("{0} = {1}", "ShiftKeyPressed", e.ShiftKeyPressed );
messageBoxCS.AppendFormat("{0} = {1}", "EventType", e.EventType );
messageBoxCS.AppendFormat("{0} = {1}", "ReturnValue", e.ReturnValue );
messageBoxCS.AppendFormat("{0} = {1}", "FromElement", e.FromElement );
messageBoxCS.AppendFormat("{0} = {1}", "ToElement", e.ToElement );
MessageBox.Show(messageBoxCS.ToString(), "Click Event" );

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.