Heybo Blog

If you look at me when I'm talking, you'll see what I'm saying ... about Tech and .NET discoveries!

My Links

News

Story Categories

Archives

Post Categories

Image Galleries

Login

Blog Stats

Links

Personal Websites

Detect an ‘Enter’ key press

To detect an ‘Enter’ key press you must understand basic terminology.

A KeyPressEventArgs specifies the character key when the user presses it.  A KeyPress event occurs when the key is pressed. The KeyDown event precedes the KeyPress event.  The KeyUp event occurs when the user releases the key. While a user is holding the key, duplicate KeyDown and KeyPress events occur each time the character repeats. With each KeyPress event, a KeyPressEventArgs is passed. A KeyEventArgs is passed with each KeyDown and KeyUp event. Also KeyEventArgs carries information about whether any modifier keys (CTRL, SHIFT, or ALT) were pressed along with another key.

 

The following example illustrates using the KeyPressEventArgs to detect and enter key press. I am using a form with a Textbox

public class theKeyPress

 {

private TextBox textBox1 = new TextBox();

private void theKeyCounter(object sender, KeyPressEventArgs ar)

{

switch(ar.KeyChar)

{ case '\r': MessageBox.Show(“Enter Key Pressed!”); break ;

}

}

?>

posted on Friday, March 26, 2004 11:23 AM

Feedback

# re: Detect an ‘Enter’ key press 8/30/2005 3:40 AM t.one

thanks, man!

Title  
Name  
Url
Comments   
Protected by Clearscreen.SharpHIPEnter the code you see: