Set focus on tab control

ankita

New member
Joined
Apr 1, 2008
Messages
2
Programming Experience
1-3
Hi all,
I am working on vb.net 2005,I have a problem that i want to set focus on tab control while pressing cntrl+tab,I dont know how to use combination of keys,I am trying to code in key_down() event but it is not worked.......
Help me if u can,

Thanx,:confused:
 
For form to get key events you have to select KeyPreview property to True.

KeyDown is not wise, have you tried holding a key down in Notepadddddddddddddd or other text editor? KeyUp is better, it only happens once.

In the Key event like other events you should inspect the 'e' parameter, here you can find much relevant information regarding the event. Here for example you want Control modifier key and find e.Control as Boolean value, the tooltip info tell you this is True if Control key is held during the key event. Further there is e.KeyCode as Keys value. Keys type is an enumeration containing all the key values.

Browsing the TabControl class members in documentation it is also possible to find that Select method should be used to give focus to it. Actually it is very likely you would have found the Focus method first, then if reading the description you see that they say you should use the Select method.

So this give the following:

VB.NET:
Private Sub theForm_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    If e.Control AndAlso e.KeyCode = Keys.Tab Then
        Me.TabControl1.Select()
    End If
End Sub
 
Back
Top