• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Trap all key strokes

If my form is not in edit mode I want to cancel all keystrokes.  How do I do that?

Thanks
0
Moed
Asked:
Moed
  • 3
  • 2
1 Solution
 
MoedAuthor Commented:
One additional note:  I still want to be able to tab out of the field
0
 
theGhost_k8Database ConsultantCommented:
   Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Try
            Select Case m.Msg
                Case WM_KEYDOWN
                    Exit Sub
                Case WM_KEYUP
                    Exit Sub
            End Select
            MyBase.WndProc(m)

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        MyBase.WndProc(m)
    End Sub
0
 
theGhost_k8Database ConsultantCommented:
or
 just set e=nothing on forms keypress event
0
 
MoedAuthor Commented:
Thanks.  Worked perfect.
0
 
MoedAuthor Commented:
Just for clarification if e = nothing or e.handled is used this line

MyBase.KeyPreview = True

needs added to the form load event.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now