Connor Albright
Connor Albright

Reputation: 743

Detecting ctrl+tab keypress

How do I detect a CtrlTab keypress?

Reason for asking: I want to stop a user from changing tabs in a tab control.

Upvotes: 1

Views: 552

Answers (1)

Hans Passant
Hans Passant

Reputation: 942518

Filtering key messages isn't very productive. You would also have to filter ShiftCtrlTab, CtrlPageDn and CtrlPageUp. Just prevent tab changes by implementing the Selecting event. Like this:

Public Class Form1
    Private allowTabChanges As Boolean

    Private Sub TabControl1_Selecting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
        If Not allowTabChanges then e.Cancel = True
    End Sub
End Class

Set allowTabChanges to true and back to false in any of your own code that wants to change the active tab page. The key filtering method is described in this answer.

Upvotes: 3

Related Questions