943,982 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 27520
  • VB.NET RSS
May 7th, 2005
0

Form1.KeyDown Event Problems

Expand Post »
When using the Form1.KeyDown, keystrokes don't seem to register.

For example, the Click works fine:
VB.NET Syntax (Toggle Plain Text)
  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:

VB.NET Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Khishin is offline Offline
23 posts
since Jan 2005
May 14th, 2005
0

Re: Form1.KeyDown Event Problems

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
May 24th, 2005
0

Re: Form1.KeyDown Event Problems

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
makatzena is offline Offline
2 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Return a value from form2 to form1
Next Thread in VB.NET Forum Timeline: Application Block in asp.net using vb.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC