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

適用於

另請參閱