Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

Keyboard events not firing...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Man From The Moon - 19 Dec 2004 21:02 GMT
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?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.