Solved

Disabling keys on the keyboard  for a project using a tab control in vb.net

Posted on 2006-06-14
3
455 Views
Last Modified: 2007-12-19
I have a vb.net Windows app heavily using the tab control.  I would like the user to navigate to the tab by actually clicking on the tab.  I noticed that the arrow keys will advance to the next tab.  Is there a way to disable those keys.  I realize that I might be able to disable the tab and enable on the click event but that alone is a little bit undesirable because I am already disabling certain tabs as a result of applying access rights.  Is there another way?
0
Comment
Question by:garyinmiami2003
3 Comments
 
LVL 2

Assisted Solution

by:shy_talk
shy_talk earned 100 total points
ID: 16902499
The following code will cancel any keypress on the form.

Public Class Form1

 Private Sub Form1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

      e.Handled = True
   End Sub
End Class


If you want to prevent specific keypresses then this should get you started, from the VB help:
   Private Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
        ' The keypressed method uses the KeyChar property to check
        ' whether the ENTER key is pressed.

        ' If the ENTER key is pressed, the Handled property is set to true,
        ' to indicate the event is handled.

        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            e.Handled = True
        End If
    End Sub 'keypressed

Good luck
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 400 total points
ID: 16902626
Use...

Public Class Form1

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Select Case keyData
            Case Keys.Left, Keys.Right
                Dim ctrl As Control = Me.ActiveControl
                If (Not (ctrl Is Nothing)) AndAlso (TypeOf ctrl Is TabControl) Then
                    Return True
                End If

        End Select

        Return False
    End Function

End Class
0
 

Author Comment

by:garyinmiami2003
ID: 16905055
My thanks to you both.  To Idle_Mind:  That worked great

Many thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question