Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trap all key strokes

Posted on 2006-11-08
5
Medium Priority
?
248 Views
Last Modified: 2010-04-23
If my form is not in edit mode I want to cancel all keystrokes.  How do I do that?

Thanks
0
Comment
Question by:Moed
  • 3
  • 2
5 Comments
 
LVL 2

Author Comment

by:Moed
ID: 17897216
One additional note:  I still want to be able to tab out of the field
0
 
LVL 21

Expert Comment

by:K V
ID: 17897334
   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
 
LVL 21

Accepted Solution

by:
K V earned 200 total points
ID: 17897336
or
 just set e=nothing on forms keypress event
0
 
LVL 2

Author Comment

by:Moed
ID: 17900443
Thanks.  Worked perfect.
0
 
LVL 2

Author Comment

by:Moed
ID: 17900473
Just for clarification if e = nothing or e.handled is used this line

MyBase.KeyPreview = True

needs added to the form load event.  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

972 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