Solved

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

Posted on 2006-06-14
3
422 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now