Disable Ctrl+Tab in Window Form

Many of time we want to stop user from moving from one child form to another child in a mdi form using Ctrl+Tab or stop user from moving from one tabpage to another tabpage in TabControl control. Then the most simple way to do this is to override the ProcessCmdKey in the form.

Description of ProcessCmdKey

ProcessCmdKey is a method in .NET which process the command key. This method is called during message preprocessing to handle command keys. Command keys are keys that always take precedence over regular input keys. The method return true to indicate that it has processed the command key, or false to indicate that the key is not a command key. This method is only called when the control is hosted in a Windows Forms application or as an ActiveX control.


Code to disable Ctrl+Tab


Public Class Form1

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = (Keys.Control Or Keys.Tab) Then
Return True
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End Function

End Class


Comments

Guest Author: Zil-e-Huma25 Apr 2012

It does not help because firstly we want some thing like KeyData == keys.Tab && KeyData == keys.Control because we are pressing both the keys at a time. Whatever may be the reason but it does not seem to be working at the moment.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: