PreviewKeyDownEventArgs PreviewKeyDownEventArgs PreviewKeyDownEventArgs PreviewKeyDownEventArgs Class

定义

PreviewKeyDown 事件提供数据。Provides data for the PreviewKeyDown event.

public ref class PreviewKeyDownEventArgs : EventArgs
public class PreviewKeyDownEventArgs : EventArgs
type PreviewKeyDownEventArgs = class
    inherit EventArgs
Public Class PreviewKeyDownEventArgs
Inherits EventArgs
继承
PreviewKeyDownEventArgsPreviewKeyDownEventArgsPreviewKeyDownEventArgsPreviewKeyDownEventArgs

示例

下面的代码示例演示如何使用此类型。The following code example demonstrates the use of this type. 在此示例中, 事件处理程序报告PreviewKeyDown事件的发生。In the example, an event handler reports on the occurrence of the PreviewKeyDown 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.

若要运行示例代码, 请将其粘贴到一个项目中, 该项目包含从Control继承的类型的实例, 如ComboBox Button或。To run the example code, paste it into a project that contains an instance of a type that inherits from Control, such as a Button or ComboBox. 然后命名该实例Control1 , 并确保事件处理程序PreviewKeyDown与事件相关联。Then name the instance Control1 and ensure that the event handler is associated with the PreviewKeyDown event.

private void Control1_PreviewKeyDown(Object sender, PreviewKeyDownEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Alt", e.Alt );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Control", e.Control );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "KeyCode", e.KeyCode );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "KeyValue", e.KeyValue );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "KeyData", e.KeyData );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Modifiers", e.Modifiers );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Shift", e.Shift );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "IsInputKey", e.IsInputKey );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "PreviewKeyDown Event" );
}
Private Sub Control1_PreviewKeyDown(sender as Object, e as PreviewKeyDownEventArgs) _ 
     Handles Control1.PreviewKeyDown

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Alt", e.Alt)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Control", e.Control)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "KeyCode", e.KeyCode)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "KeyValue", e.KeyValue)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "KeyData", e.KeyData)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Modifiers", e.Modifiers)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Shift", e.Shift)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "IsInputKey", e.IsInputKey)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"PreviewKeyDown Event")

End Sub

注解

有关处理事件的详细信息, 请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

构造函数

PreviewKeyDownEventArgs(Keys) PreviewKeyDownEventArgs(Keys) PreviewKeyDownEventArgs(Keys) PreviewKeyDownEventArgs(Keys)

使用指定的密钥初始化 PreviewKeyDownEventArgs 类的新实例。Initializes a new instance of the PreviewKeyDownEventArgs class with the specified key.

属性

Alt Alt Alt Alt

获取一个值,该值指示是否曾按下 Alt 键。Gets a value indicating whether the ALT key was pressed.

Control Control Control Control

获取一个值,该值指示是否曾按下 Ctrl 键。Gets a value indicating whether the CTRL key was pressed.

IsInputKey IsInputKey IsInputKey IsInputKey

获取或设置一个值,该值指示一个键是否为常规输入键。Gets or sets a value indicating whether a key is a regular input key.

KeyCode KeyCode KeyCode KeyCode

获取 KeyDownKeyUp 事件的键盘代码。Gets the keyboard code for a KeyDown or KeyUp event.

KeyData KeyData KeyData KeyData

获取与键修饰符(如 SHIFT、CONTROL 和 KeyDownKeyUp 事件的 ALT 键)结合使用的键代码。Gets the key code combined with key modifiers such as the SHIFT, CONTROL, and ALT keys for a KeyDown or KeyUp event.

KeyValue KeyValue KeyValue KeyValue

获取 KeyDownKeyUp 事件的键盘值。Gets the keyboard value for a KeyDown or KeyUp event.

Modifiers Modifiers Modifiers Modifiers

获取 KeyDownKeyUp 事件的修饰符标志。Gets the modifier flags for a KeyDown or KeyUp event.

Shift Shift Shift Shift

获取一个值,该值指示是否曾按下 Shift 键。Gets a value indicating whether the SHIFT key was pressed.

方法

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)

适用于

另请参阅