capture keystroke before display in textbox

A

Ada

hi folks,

i've been searching for solution for a couple days now.
hoping someone here have an easy solution.

i have a winform with one textbox.
i'm trying to capture the keystroke and display the ASCII code
in MsgBox before it displays in the textbox.

i tried KeyValue and KeyCode in KeyPress event but those seem to display
only the capital letter.
when i input lowercase, the KeyValue is still the same.
example, KeyValue of "A" or "a" are the same value of 65.

any suggestions appreciated.

tia,
 
A

Ada

thanks guys for the response.

i found the solution about an hour after posting this question.
to trap the keystroke, one needs to set the boolean to true in
e.handled for KeyUp, KeyDown and KeyPress.

as to the question why i wanted to display the keystroke in MessageBox...
i can't get the correct ASCII code for capital and lower case letter.
seems like it always display the same KeyValue.
and the KeyValue always for the capital letter.
and yes, the CAPS LOCK is OFF.

anyhow, problem solved now.
case closed. :)




Peter Duniho said:
hi folks,

i've been searching for solution for a couple days now.
hoping someone here have an easy solution.

i have a winform with one textbox.
i'm trying to capture the keystroke and display the ASCII code
in MsgBox before it displays in the textbox.

i tried KeyValue and KeyCode in KeyPress event but those seem to display
only the capital letter. [...]

If you are looking at a KeyValue and KeyCode property, you're not handling
the KeyPress event.

On the other hand, if you do handle the KeyPress event, you will get a
character code, just as you seem to want.

I don't think you should be using MsgBox in C# (the proper
System.Windows.Forms class is MessageBox), and it's not clear to me why
it's useful to have a MsgBox or MessageBox display with each key-press.
But if that's what you want, it should work as long as you handle the
right event.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top