KeyEventArgs.Key 属性

定义

获取与事件关联的键盘键。

public:
 property System::Windows::Input::Key Key { System::Windows::Input::Key get(); };
public System.Windows.Input.Key Key { get; }
member this.Key : System.Windows.Input.Key
Public ReadOnly Property Key As Key

属性值

Key

事件引用的 Key

示例

以下示例创建 并 KeyEventHandler 检查与 KeyEventArgs 关联的键是否为 键 Return

private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Return)
    {
        textBlock1.Text = "You Entered: " + textBox1.Text;
    }
}
Private Sub OnKeyDownHandler(ByVal sender As Object, ByVal e As KeyEventArgs)
    If (e.Key = Key.Return) Then
        textBlock1.Text = "You Entered: " + textBox1.Text
    End If
End Sub

适用于

另请参阅