C#:Handling Enter key press event for textbox.

If you want to do something when focus is on textbox and and user press ‘Enter’ key, do the following way:

private void txt1_KeyPress(object sender, KeyPressEventArgs e)</code>
{
 if (e.KeyChar == (char)Keys.Enter)
 {
    //do something
 }
}

where txt1 is textbox

Published in: on August 5, 2009 at 3:31 pm  Leave a Comment  
Tags: , , ,