Shortcuts on the TabControl

GornHorse

Member
Joined
Jun 8, 2004
Messages
5
Programming Experience
5-10
Hi There!
On a windows form, I have a tabcontrol with several tabpages on it. What I want to do is be able to have "F1" set as a shortcut to the first tabpage, "F2" for the second etc. for all the tabpages.

I tried setting up a keypress event for the actual form, but it never fired. Can I just set up a shortcut? Or, if not, how on earth do I catch the keypress event.

Note that the form is an mdiChild, but it is this mdiChild that has the tabcontrol on it.

Please provide some feedback asap.


Thanks,
Mish
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Use the keyPress event and set the 'KeyPreview' property of the form to True.

Please provide feedback to this feedback ASAP. ;)

Thanks.
 

GornHorse

Member
Joined
Jun 8, 2004
Messages
5
Programming Experience
5-10
Hi There,
Thanks for the feedback, but I actually already sort of figured out the best way of doing it. For those who would like to know, I put the following within the code of my form that contains the TabControl.


_________________________________________________________________

VB.NET:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keydata As Keys) As Boolean
Dim WorkID As String = tbG_WorkID.Text 
Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104
 
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
 
Select Case (keydata)
 
Case Keys.F1
Me.tabSearch.Focus()
MAD_WorkTabs.SelectedIndex = 0
 
Case Keys.F2
Try
Me.ShowGeneralTab(WorkID)
Catch ex As Exception
End Try
 
Case Keys.F3
Try
If Not REPSLOADED Then
	 Me.Cursor.Current = Windows.Forms.Cursors.WaitCursor
	 ShowRepsTab(WorkID)
	 REPSLOADED = True
	 Me.Cursor.Current = Windows.Forms.Cursors.Default
End If
MAD_WorkTabs.SelectedIndex = 2
Catch ex As Exception
End Try
 
Case Keys.F4
Try
If Not TEACHERSLOADED Then
	 Me.Cursor.Current = Windows.Forms.Cursors.WaitCursor
	 ShowTeachersTab(WorkID)
	 TEACHERSLOADED = True
	 Me.Cursor.Current = Windows.Forms.Cursors.Default
End If
MAD_WorkTabs.SelectedIndex = 3
Catch ex As Exception
End Try
 
Case Keys.F5
Try
If Not VISITSLOADED Then
	 Me.Cursor.Current = Windows.Forms.Cursors.WaitCursor
	 ShowVisitsTab(WorkID)
	 VISITSLOADED = True
	 Me.Cursor.Current = Windows.Forms.Cursors.Default
End If
MAD_WorkTabs.SelectedIndex = 4
Catch ex As Exception
End Try
 
Case Keys.F6
MAD_WorkTabs.SelectedIndex = 5
 
Case Keys.F7
MAD_WorkTabs.SelectedIndex = 6
 
Case (Keys.Control Or Keys.M)
myMainFrm.MembersPressed()
 
Case (Keys.Control Or Keys.W)
myMainFrm.WorkPressed()
 
Case (Keys.Control Or Keys.T)
myMainFrm.TransactionPressed()
 
Case (Keys.Control Or Keys.O)
myMainFrm.OtherPressed()
 
End Select
End If
 
End Function
 
Top Bottom