Link to home
Start Free TrialLog in
Avatar of Moe DeShong
Moe DeShongFlag for United States of America

asked on

Trap all key strokes

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

Thanks
Avatar of Moe DeShong
Moe DeShong
Flag of United States of America image

ASKER

One additional note:  I still want to be able to tab out of the field
Avatar of theGhost_k8
   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
ASKER CERTIFIED SOLUTION
Avatar of theGhost_k8
theGhost_k8
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.  Worked perfect.
Just for clarification if e = nothing or e.handled is used this line

MyBase.KeyPreview = True

needs added to the form load event.