Keyboard events not firing...

Q

Quimbly

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.


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);


And for implementations I simply have:

[code:1:06ec7fb86f]
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:1:06ec7fb86f]

The message boxes are not coming up and the status bar is not changing
when I hit keys. What am I doing wrong?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
G

Guest

Quimbly,

I believe that your code is fine but you are probably not putting the wireup
for your event handlers in the correct place. Try putting the wireup in the
form load event and then run your code.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top