Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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