Your code is working, you message box is just displaying the tab character i.e. blank space.
Cast to int and you will see it's working:
MessageBox.Show("button: " + (int) e.KeyChar);
EDIT: Otherwise look at this code:
public Form1()
{
InitializeComponent();
this.KeyPress += new KeyPressEventHandler(this.Form1_KeyPress);
this.KeyDown += new KeyEventHandler(this.Form1_KeyDown);
}
// Keypress only handles keys in the ascii range
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show("KeyPress: " + (int) e.KeyChar);
}
// Keydown will work for all keys
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("KeyDown: " + e.KeyCode);
}
ParmesanCodice
2009-09-23 16:43:16