My KeyDown / KeyUp / KeyPress events are not firing; I can't figure out what
I'm doing wrong. The code I'm using is basically straight from the manual.
"this" refers to my Windows.Forms.Form object.
[CODE]
this.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown);
this.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyUp);
[/CODE]
And for implementations I simply have:
[CODE]
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("KeyDown Event!");
statusBar.Text = e.KeyCode.ToString();
}
private void MainForm_KeyUp(object sender, KeyEventArgs e)
{
MessageBox.Show("KeyUp Event!");
statusBar.Text = e.KeyCode.ToString();
}
private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show("KeyPress Event!");
statusBar.Text = e.KeyChar.ToString();
}
[/CODE]
The message boxes are not coming up and the status bar is not changing when
I hit keys. What am I doing wrong?
Dmitriy Lapshin [C# / .NET MVP] - 20 Dec 2004 08:42 GMT
Hi,
Try setting the form's KeyPreview property to 'true'.

Signature
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
> My KeyDown / KeyUp / KeyPress events are not firing; I can't figure out
> what
[quoted text clipped - 35 lines]
> when
> I hit keys. What am I doing wrong?
Jakob Christensen - 20 Dec 2004 08:45 GMT
See my answer in the dotnet.general group.
/Jakob
> My KeyDown / KeyUp / KeyPress events are not firing; I can't figure out what
> I'm doing wrong. The code I'm using is basically straight from the manual.
[quoted text clipped - 31 lines]
> The message boxes are not coming up and the status bar is not changing when
> I hit keys. What am I doing wrong?