Disabling default spacebar key press event for a button

  • Thread starter Thread starter prema askme
  • Start date Start date
P

prema askme

Hi

In windows forms, when focus is given to a button, the spacebar is one
of the default keys that can be used to trigger the button. I would like
to override this behaviour.

Does anybody know how I could do this? I still want the user to be able
to click the button with an enter key but just not with the spacebar.

Does the solution involve using the keypreview property? i've read
something similar in an earlier question..

Thanks!
PREMA
 
* prema askme said:
In windows forms, when focus is given to a button, the spacebar is one
of the default keys that can be used to trigger the button. I would like
to override this behaviour.

Does anybody know how I could do this? I still want the user to be able
to click the button with an enter key but just not with the spacebar.

Does the solution involve using the keypreview property? i've read
something similar in an earlier question..

Untested:

\\\
Public Class MyButton
Inherits Button

Protected Overrides Function ProcessDialogKey( _
ByVal keyData As System.Windows.Forms.Keys) As Boolean

If keyData = Keys.Space Then
Return True
Else
Return MyBase.ProcessDialogKey(keyData)
End If
End Function
End Class
///
 
Back
Top