WPF: A TextBox that has an event that fires when the Enter Key is pressed

后端 未结 5 1785
走了就别回头了
走了就别回头了 2021-01-30 18:10

Instead of attaching a PreviewKeyUp event with each TextBox in my app and checking if the pressed key was an Enter key and then do an action, I decided

5条回答
  •  情深已故
    2021-01-30 18:43

        private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
        {
            string etr = e.Key.ToString();
    
            if (etr == "Return")
            {
                MessageBox.Show("You Press Enter");
            }
        }
    

提交回复
热议问题