|
-
May 23rd, 2009, 09:57 AM
#1
Thread Starter
Member
[RESOLVED] Cancel arrow buttons event tabcontrol
Hi,
When I click the left or right arrow buttons on the keyboard my tabcontrol tabpage changes from one tab to another.
How can I cancel the arrow buttons from changing the tab pages?
In other words how can I disable the arrow buttons when the tabpage has focus?
Is it possible to do this without extending the base class?
-
May 23rd, 2009, 10:31 AM
#2
Re: Cancel arrow buttons event tabcontrol
Set the form's keypreview property to true, and add this code for the keydown handler :
Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Left Or e.KeyCode = Keys.Right Then
e.SuppressKeyPress = True
End If
End Sub
NB this will trap the left and right arrows for all controls, you may want to check that the form's currently selected control first
Last edited by keystone_paul; May 23rd, 2009 at 10:34 AM.
Reason: added proviso about the selected control
-
May 23rd, 2009, 10:36 AM
#3
Re: Cancel arrow buttons event tabcontrol
This would trap it only for the specific control :
Code:
If Me.ActiveControl Is TabControl1 Then
If e.KeyCode = Keys.Left Or e.KeyCode = Keys.Right Then
e.SuppressKeyPress = True
End If
End If
-
May 24th, 2009, 12:10 AM
#4
Re: Cancel arrow buttons event tabcontrol
Paul's solution is correct, although you would be better off just handling the KeyDown event of the TabControl rather than the form. I'd always recommend using OrElse rather than Or too.
-
May 24th, 2009, 02:55 AM
#5
Thread Starter
Member
Re: Cancel arrow buttons event tabcontrol
Awesome, thanks heaps guys that worked a treat.
-
May 24th, 2009, 06:27 AM
#6
Re: Cancel arrow buttons event tabcontrol
 Originally Posted by jmcilhinney
Paul's solution is correct, although you would be better off just handling the KeyDown event of the TabControl rather than the form. I'd always recommend using OrElse rather than Or too.
Quite right - for some reason I had in the back of my mind that there was some issue with trapping special keys on the tabcontrol but I've just tried it and I was mistaken.
You would indeed be better off just applying the event to the tabcontrol rather than the form.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|