Windows Develop Bookmark and Share   
 index > Windows Forms General > Stop Ctrl+Tab in the tabcontrol
 

Stop Ctrl+Tab in the tabcontrol

Im using VB.NET and i do not want users to be able to cycle through the tab pages using Ctrl+Tab (or Ctrl+Shift+Tab).

I tried using the keydown event and setting

e.SuppressKeyPress = True

But no dice.

nizmo  Thursday, September 13, 2007 1:07 AM
Add a new class to your project and paste the code shown below. Build. Drop the new control from the top of your toolbox onto your form. This code prevents the TabControl.OnKeyDown() method from seeing the keystroke.

Public Class MyTabControl
Inherits TabControl

Protected Overrides Sub OnKeyDown(ByVal key As System.Windows.Forms.KeyEventArgs)
If key.KeyData = (Keys.Tab Or Keys.Control) Or key.KeyData = (Keys.Tab Or Keys.Control Or Keys.Shift) Then
key.Handled = True
Else
MyBase.OnKeyDown(key)
End If
End Sub

End Class
nobugz  Thursday, September 13, 2007 3:17 AM
Add a new class to your project and paste the code shown below. Build. Drop the new control from the top of your toolbox onto your form. This code prevents the TabControl.OnKeyDown() method from seeing the keystroke.

Public Class MyTabControl
Inherits TabControl

Protected Overrides Sub OnKeyDown(ByVal key As System.Windows.Forms.KeyEventArgs)
If key.KeyData = (Keys.Tab Or Keys.Control) Or key.KeyData = (Keys.Tab Or Keys.Control Or Keys.Shift) Then
key.Handled = True
Else
MyBase.OnKeyDown(key)
End If
End Sub

End Class
nobugz  Thursday, September 13, 2007 3:17 AM

Excellent, works perfectly... just like all the answers yougive me!

nizmo  Thursday, September 13, 2007 3:23 AM

Hi,


When migrating project from VB to Vb.Net the TAB control behaviour is not good.Tab pages is not opening in the tab control by pressing Tab Key in VB.Net where as in VB it is working fine.Please help to solve the problem

Thanks in Advance

Vini

Treesa  Thursday, November 22, 2007 7:45 AM

You can use google to search for other answers

Custom Search

More Threads

• problem with visual studio ,NET deployment!
• Column Selection
• How to show MDI Child Form in a SplitContainer Panel?
• Retrieve data from a database and insert it into a listbox
• Disabling Scroll in a RichTextBox
• windows 2000 loses copy paste option while uninstalling my .net application
• ToolStripItem Container
• Multiple applications printing
• draw rectangle with rounded angles
• WebBrowser control, catching Backspace