cancel/Block the TABKEY

M

Mobileboy36

Hi group,

I have got a custom textbox class.

How can I cancel/Block the TABKEY, to avoid a user can exit the the custom
textbox.

Please don't propose to set tabstop from the other controls to false because
can't do that for certain reasons.

I already tried this code INSIDE my custom textbox class:



Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)

If e.KeyChar = Chr(System.Windows.Forms.Keys.Tab) Then

e.Handled = True

Else

e.Handled = False

MyBase.OnKeyPress(e)

End If

End Sub





Protected Overrides Sub OnKeyDown(ByVal e As
System.Windows.Forms.KeyEventArgs)



If e.KeyCode = System.Windows.Forms.Keys.Tab Then

e.Handled = True

Else

e.Handled = False

MyBase.OnKeyUp(e)

End If







End Sub



It does not work. How can I achieve my purpose?



Best regards,

Mobile boy
 
J

Jerod Houghtelling

Hi group,

I have got a custom textbox class.

How can I cancel/Block the TABKEY, to avoid a user can exit the the custom
textbox.

Please don't propose to set tabstop from the other controls to false because
can't do that for certain reasons.

I already tried this code INSIDE my custom textbox class:

Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)

If e.KeyChar = Chr(System.Windows.Forms.Keys.Tab) Then

e.Handled = True

Else

e.Handled = False

MyBase.OnKeyPress(e)

End If

End Sub

Protected Overrides Sub OnKeyDown(ByVal e As
System.Windows.Forms.KeyEventArgs)

If e.KeyCode = System.Windows.Forms.Keys.Tab Then

e.Handled = True

Else

e.Handled = False

MyBase.OnKeyUp(e)

End If

End Sub

It does not work. How can I achieve my purpose?

Best regards,

Mobile boy

Is your form's KeyPreview set to true?
 

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