KeyDown event

G

Guest

I am struggling to get the keydown event for checkboxes to work when pressing
down arrow and enter. The so-called help talks about overriding the
IsInputKey method for the controls, but doesn't give an example. How do I
override a control's method?
TIA
 
A

Armin Zingler

Helen Trim said:
I am struggling to get the keydown event for checkboxes to work when
pressing down arrow and enter. The so-called help talks about
overriding the IsInputKey method for the controls, but doesn't give
an example. How do I override a control's method?


The Enter key is caught by the KeyDown event by default.

If you want to override a method, derive a class from the Checkbox class and
override the method by choosing "overrides" and "IsInputKey" from the
comboboxes at the top of the code editor. Results in

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

If keyData = Keys.Down Then
Return True
Else
Return MyBase.IsInputKey(keyData)
End If

End Function


If you want to use the designer to replace the standard Checkbox by your own
derived Checkbox, you have to compile, add it to the toolbox and put it on
the Form. Unfortunatelly, only own controls derived from UserControl are put
automatically in the toolbox.


Armin
 
G

Guest

Hello Armin

You're right about the Enter key. Thanks for your help, I think I
understand now how to use inheritance and overrides.
 

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