KeyDown Event is not catching Function & Tab key

  • Thread starter Thread starter M.M Ansari
  • Start date Start date
M

M.M Ansari

Hi All,

why keydown event is functioning properly as it was in VB6.? I have the
following declaration. It is catchig Alphanumeric Keys but not the function
and tab key. following is the syntax;

Private Sub cmb1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles cmb1.KeyDown
If e.KeyCode = Keys.Tab Then

messagebox.show "Tab is pressed"

End If

End Sub

any reason?

thanks in advance.

Ansai
 
Hey Ansai

TAB is handled by controls automatically. Therefore pressing tab will not raise the KeyDown and KeyPress events. To overcome this you must override the method Control.IsInputKey in each control on your form where you want to receive KeyDown events for the TAB key

For example

public class ButtonEx : System.Windows.Forms.Button

protected override bool IsInputKey(Keys keyData

if (Keys.Tab == keyData
return true
return base.IsInputKey (keyData)




You can then use ButtonEx instead of System.Windows.Forms.Button and receive the KeyDown event whenever a user presses the TAB key when the button is selected

Regards, Jakob.
 
* "M.M Ansari said:
why keydown event is functioning properly as it was in VB6.? I have the
following declaration. It is catchig Alphanumeric Keys but not the function
and tab key. following is the syntax;

Private Sub cmb1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles cmb1.KeyDown
If e.KeyCode = Keys.Tab Then

messagebox.show "Tab is pressed"

End If

Have a look at the form's 'Process*Key' methods.
 
Back
Top