Key Down Trapping





10
Date Submitted Wed. Sep. 27th, 2006 7:35 PM
Revision 1 of 1
Beginner finch
Tags CSharp | Down | Key | Trapping
Comments 1 comments
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.
            }
        }
 

ned f

Comments

Comments Use KeyUp instead
Fri. May. 25th, 2007 2:24 PM    Beginner Jax

Voting