PreviewKeyDownEventArgs 类    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 PreviewKeyDown 事件提供数据。
public ref class PreviewKeyDownEventArgs : EventArgspublic class PreviewKeyDownEventArgs : EventArgstype PreviewKeyDownEventArgs = class
    inherit EventArgsPublic Class PreviewKeyDownEventArgs
Inherits EventArgs- 继承
示例
下面的代码示例演示如何使用此类型。 在此示例中,事件处理程序报告事件的发生情况 PreviewKeyDown 。 此报告可帮助你了解事件发生的时间,并可以帮助你进行调试。 若要报告多个事件或频繁发生的事件,请考虑将 ShowConsole.WriteLine 消息替换为 或将消息追加到多行 TextBox。
若要运行示例代码,请将其粘贴到包含继承自 Control的类型的实例(如 Button 或 ComboBox)的项目中。 然后命名实例 Control1 并确保事件处理程序与事件 PreviewKeyDown 相关联。
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
注解
有关处理事件的详细信息,请参阅 处理和引发事件。
构造函数
| PreviewKeyDownEventArgs(Keys) | 使用指定的密钥初始化 PreviewKeyDownEventArgs 类的新实例。 | 
属性
| Alt | 获取一个值,该值指示是否曾按下 Alt 键。 | 
| Control | 获取一个值,该值指示是否曾按下 Ctrl 键。 | 
| IsInputKey | 获取或设置一个值,该值指示一个键是否为常规输入键。 | 
| KeyCode | |
| KeyData | 获取与键修饰符(如 SHIFT、CONTROL 和 KeyDown 或 KeyUp 事件的 ALT 键)结合使用的键代码。 | 
| KeyValue | |
| Modifiers | |
| Shift | 获取一个值,该值指示是否曾按下 Shift 键。 | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |