469,602 Members | 1,984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Keyboard events not firing...

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.Mai nForm_KeyPress);
this.KeyUp += new
System.Windows.Forms.KeyEventHandler(this.MainForm _KeyUp);
And for implementations I simply have:

[code:1:4c42e66fb0]
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:4c42e66fb0]

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
*-----------------------*
Jul 21 '05 #1
1 1582
The key events are "eaten" by the controls on your form. If you set the
KeyPreview property to true for your form, the events will be fired for the
form.

HTH, Jakob.
"Quimbly" wrote:
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.Mai nForm_KeyPress);
this.KeyUp += new
System.Windows.Forms.KeyEventHandler(this.MainForm _KeyUp);
And for implementations I simply have:

[code:1:4c42e66fb0]
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:4c42e66fb0]

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
*-----------------------*

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by JPRoot | last post: by
3 posts views Thread by Mike | last post: by
1 post views Thread by Quimbly | last post: by
reply views Thread by luc.saffre | last post: by
reply views Thread by RobKinney1 | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.