Key Down Trapping
10
This code was something I used to monitor the keys that where press while a user would be entering text into a text box in my application. I monitored and watch for the user to hit the "Enter" key and then perform some task. Handy code for chat applications.
// Place the following code into the
// #region Windows Form Designer generated code
this.txtEnter.KeyDown += new KeyEventHandler(txtEnter_KeyDown);
// Place the following function where ever the
// #region Windows Form Designer generated code
// is located or you can move it elsewhere if you like,
// but you will then need to make it public.
private void txtEnter_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
// Your code here.
}
}






It's therefore better to use KeyUp for such things as confirmations.