Form1.KeyDown Event Problems

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 23
Reputation: Khishin is an unknown quantity at this point 
Solved Threads: 0
Khishin Khishin is offline Offline
Newbie Poster

Form1.KeyDown Event Problems

 
0
  #1
May 7th, 2005
When using the Form1.KeyDown, keystrokes don't seem to register.

For example, the Click works fine:
  1. Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
  2. MsgBox("Hello")
  3. End Sub

That will display the message box when the form is clicked, but if you change it to:

  1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
  2. MsgBox("Hello")
  3. End Sub

I can't seem to get the message box to appear.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Form1.KeyDown Event Problems

 
0
  #2
May 14th, 2005
Hmn. The code looks right. I would try to change it from handling mybase though, to handling the form in question. I'm not sure if that will make a big difference or not, since I don't use .NET, but it would seem to me that the sub should handle keypress event of the form's name.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 2
Reputation: makatzena is an unknown quantity at this point 
Solved Threads: 0
makatzena makatzena is offline Offline
Newbie Poster

Re: Form1.KeyDown Event Problems

 
0
  #3
May 24th, 2005
if you want it to work you will have to put the "keypreview" property of Form1 to true. This will make keyboard events be registered on the form.

In VB6 this same property made the form's keyboard events take priority from the other controls' keyboard events. It seems to have changed

saludos
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 20140 | Replies: 2
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC