Intercepting Ctrl+Tab in TabControl

O

Oenone

I'm using a TabControl to facilitate a wizard-style form, using some of the
techniques described here:

http://www.codeproject.com/cs/miscctrl/WizardTab.asp

For the most part I have this working very nicely, and using the information
in the comments below the article I've managed to completely hide the tab
headers without resorting to "drawing over" them.

What I've not managed to solve however is the fact that the user can press
Ctrl+Tab (and Ctrl+Shift+Tab) to cycle forwards (and backwards) through the
tabs, completely outside of the control of my application. I obviously want
the wizard to be in complete control of which tab is being displayed at all
times.

Can anyone suggest a way that I could intercept this keyboard combination
and prevent it from affecting the tabcontrol? I've tried putting code into
the TabControl_KeyDown event and setting the e.Handled property to True, but
although the code does get called, the tab control has already changed tab
by the time the event is fired.

My thanks in advance,
 
K

Ken Tucker [MVP]

Hi,

I created a tab control which allows you to cancel a tab page
change. maybe that will help.

http://www.onteorasoftware.com/Downloads/onteoratabcontrol.zip

Ken
---------------------
I'm using a TabControl to facilitate a wizard-style form, using some of the
techniques described here:

http://www.codeproject.com/cs/miscctrl/WizardTab.asp

For the most part I have this working very nicely, and using the information
in the comments below the article I've managed to completely hide the tab
headers without resorting to "drawing over" them.

What I've not managed to solve however is the fact that the user can press
Ctrl+Tab (and Ctrl+Shift+Tab) to cycle forwards (and backwards) through the
tabs, completely outside of the control of my application. I obviously want
the wizard to be in complete control of which tab is being displayed at all
times.

Can anyone suggest a way that I could intercept this keyboard combination
and prevent it from affecting the tabcontrol? I've tried putting code into
the TabControl_KeyDown event and setting the e.Handled property to True, but
although the code does get called, the tab control has already changed tab
by the time the event is fired.

My thanks in advance,
 
M

Mick Doherty

Add the following code to your form:

\\\
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, _
ByVal keyData As Keys) As Boolean
If TypeOf ActiveControl Is TabControl Then
If CBool(keyData And Keys.Control Or Keys.Tab) Then
Return True
End If
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
///
 

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