HtmlElementEventArgs HtmlElementEventArgs HtmlElementEventArgs HtmlElementEventArgs Class

定义

HtmlDocumentHtmlElement 上定义的事件提供数据。Provides data for the events defined on HtmlDocument and HtmlElement.

public ref class HtmlElementEventArgs sealed : EventArgs
public sealed class HtmlElementEventArgs : EventArgs
type HtmlElementEventArgs = class
    inherit EventArgs
Public NotInheritable Class HtmlElementEventArgs
Inherits EventArgs
继承
HtmlElementEventArgsHtmlElementEventArgsHtmlElementEventArgsHtmlElementEventArgs

示例

下面的代码示例演示如何使用此类型。The following code example demonstrates the use of this type. 在此示例中, 事件处理程序报告Click事件的发生。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. 若要报告多个事件或频繁发生的事件, 请考虑ShowConsole.WriteLine消息替换为多行或将TextBox其追加到多行。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.

若要运行示例代码, 请将其粘贴到包含名为HtmlDocument HtmlDocument1的类型的实例的项目中。To run the example code, paste it into a project that contains an instance of type HtmlDocument named HtmlDocument1. 然后, 确保事件处理程序与Click事件相关联。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.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ClientMousePosition", e.ClientMousePosition );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "OffsetMousePosition", e.OffsetMousePosition );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "MousePosition", e.MousePosition );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "BubbleEvent", e.BubbleEvent );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "KeyPressedCode", e.KeyPressedCode );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "AltKeyPressed", e.AltKeyPressed );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "CtrlKeyPressed", e.CtrlKeyPressed );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ShiftKeyPressed", e.ShiftKeyPressed );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "EventType", e.EventType );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ReturnValue", e.ReturnValue );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "FromElement", e.FromElement );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ToElement", e.ToElement );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "Click Event" );
}
Private Sub HtmlDocument1_Click(sender as Object, e as HtmlElementEventArgs) _ 
     Handles HtmlDocument1.Click

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

End Sub

注解

HtmlElementEventArgs当针对非托管 html DOM 进行window.event编程或为 HTML 页编写活动脚本时, 封装对象上找到的相同信息。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.

在大多数情况下, 您可以ToElement使用查找正在接收事件操作的 html 元素, 并FromElement查找当前事件导致我们离开的 html 元素。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. 但是, 并非每个事件都提供了这些属性的值;查看事件的托管文档或 Internet Explorer SDK 文档中的相应文档, 以了解事件是否提供此项。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.

HTML DOM 中的许多事件都将发送到其父元素, 除非已取消。Many events in the HTML DOM are sent to their parent elements unless they are cancelled. 这称为事件冒泡。This is known as event bubbling. SPAN DIV BODY如果在DIV中的内接收一次单击, 则会为第一个单击事件, 并针对, 然后对 HTML 页面的元素引发 click 事件。 SPANIf 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控制事件是否以这种方式运行。BubbleEvent controls whether an event will behave in this manner or not.

属性

AltKeyPressed AltKeyPressed AltKeyPressed AltKeyPressed

指示此事件发生时是否按下了 Alt 键。Indicates whether the ALT key was pressed when this event occurred.

BubbleEvent BubbleEvent BubbleEvent BubbleEvent

获取或设置一个值,该值指示当前事件是否以冒泡方式通过 HTML 文档对象模型的元素层次结构。Gets or sets a value indicating whether the current event bubbles up through the element hierarchy of the HTML Document Object Model.

ClientMousePosition ClientMousePosition ClientMousePosition ClientMousePosition

获取或设置鼠标指针在文档工作区中的位置。Gets or sets the position of the mouse cursor in the document's client area.

CtrlKeyPressed CtrlKeyPressed CtrlKeyPressed CtrlKeyPressed

指示此事件发生时是否按下了 Ctrl 键。Indicates whether the CTRL key was pressed when this event occurred.

EventType EventType EventType EventType

获取所引发的事件的名称。Gets the name of the event that was raised.

FromElement FromElement FromElement FromElement

获取鼠标指针正在离开的 HtmlElementGets the HtmlElement the mouse pointer is moving away from.

KeyPressedCode KeyPressedCode KeyPressedCode KeyPressedCode

获取在 KeyPressKeyDownKeyUp 事件中键入的键盘字符的 ASCII 值。Gets the ASCII value of the keyboard character typed in a KeyPress, KeyDown, or KeyUp event.

MouseButtonsPressed MouseButtonsPressed MouseButtonsPressed MouseButtonsPressed

获取 MouseDownMouseUp 事件期间单击的鼠标按钮。Gets the mouse button that was clicked during a MouseDown or MouseUp event.

MousePosition MousePosition MousePosition MousePosition

获取或设置鼠标光标相对于相对定位的父元素的位置。Gets or sets the position of the mouse cursor relative to a relatively positioned parent element.

OffsetMousePosition OffsetMousePosition OffsetMousePosition OffsetMousePosition

获取或设置鼠标光标相对于引发事件的元素的位置。Gets or sets the position of the mouse cursor relative to the element that raises the event.

ReturnValue ReturnValue ReturnValue ReturnValue

获取或设置处理的事件的返回值。Gets or sets the return value of the handled event.

ShiftKeyPressed ShiftKeyPressed ShiftKeyPressed ShiftKeyPressed

指示此事件发生时是否按下了 Shift 键。Indicates whether the SHIFT key was pressed when this event occurred.

ToElement ToElement ToElement ToElement

获取用户正将鼠标指针移向的 HtmlElementGets the HtmlElement toward which the user is moving the mouse pointer.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于

另请参阅