Wednesday, October 14, 2009

KeyPress Event and KeyStrokes

the following code segment demonstrate how to detect keystroke, specifically ENTER key in a textbox keypress event.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
   if (e.KeyChar == (char)13)
   {
   MessageBox.Show("You pressed the ENTER key.");
   }
}

--------------------------------------------------
to identify decimal equivalent of each keys, try this code:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
   int x= (int)e.KeyChar;
   MessageBox.Show(x.ToString());
}

--------------------------------------------------
***happy coding***
for more decimal representation of each character visit http://www.asciitable.com/

No comments:

Post a Comment