Problem with keyevent and buttons

T

Tomas Andersson

I created a form that has KeyPreview enabled
On this form threre is four groupboxes
and some buttons in one of the GBoxes

the keyevent works fine on all keys exept Return.
And if i remove the buttons from the form the return event works.

How do I keep the buttons and get the form to respond to Return?
Private Sub form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode <= 32 Then
Call RemoveButtons()
e.Handled = True
Else
a = a + Chr(e.KeyValue.ToString)
e.Handled = True
End If
End sub
 
A

Armin Zingler

Tomas Andersson said:
I created a form that has KeyPreview enabled
On this form threre is four groupboxes
and some buttons in one of the GBoxes

the keyevent works fine on all keys exept Return.
And if i remove the buttons from the form the return event works.

How do I keep the buttons and get the form to respond to Return?
Private Sub form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode <= 32 Then
Call RemoveButtons()
e.Handled = True
Else
a = a + Chr(e.KeyValue.ToString)
e.Handled = True
End If
End sub


I can't reproduce the problem. I don't get the enter key in keydown only if
the Form's Acceptbutton property is set. But that's ok because Enter is to
be handled by the button's click event, then. Otherwise Enter also arrives
at keydown.


Armin
 
T

Tomas Andersson

Acceptbutton property is set to (none)




Armin Zingler said:
I can't reproduce the problem. I don't get the enter key in keydown only
if the Form's Acceptbutton property is set. But that's ok because Enter is
to be handled by the button's click event, then. Otherwise Enter also
arrives at keydown.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top