473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1729
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
2
by: wesmanjunk | last post by:
does anyone know how to generate keyboard events in another application? like public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); can be used for mouse...
3
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace...
7
by: Denise | last post by:
I just realized the DataTable_RowChanging events were firing when I called Fill method of the DataAdapter! It fires TWICE for each row loaded. I thought these were only supposed to be called when...
1
by: Quimbly | last post by:
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...
0
by: luc.saffre | last post by:
Hello, I thought that I should ask here for comments on a blog entry that I wrote some weeks ago. I am sure that other people have been thinking about this, but I didn't yet find them. The...
0
by: RobKinney1 | last post by:
Hello, One of our C# apps (2.0) depends on a few events. One of them being DocumentComplete. Well, everything works fine with users that have IE 6 installed on their computers. But we noticed...
4
by: Joergen Bech | last post by:
I sometimes use delegates for broadcasting "StateChanged" events, i.e. if I have multiple forms and/or controls that need updating at the same time as the result of a change in a global/common...
13
by: andypb123 | last post by:
Hello, The onchange event fires in IE6 in a SELECT element when scrolling through the list with the up and down arrows on the keyboard. In Firefox it only fires after you hit the enter key, which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.