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: , , ,

The URI to TrackBack this entry is: https://indiandeve.wordpress.com/2009/08/05/chandling-enter-key-press-event-for-textbox/trackback/

RSS feed for comments on this post.

Leave a comment