Key_Press event

J

jayderk

Hello All,


I have this code and am using a Qwerty keyboard device

private void txtCount_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if(!(Char.IsLetterOrDigit(e.KeyChar)) && e.KeyChar != '\b')
{
e.Handled = true;
}
}

basically it ignores it if it is not a letter, digit, or backspace.

my question is :
on the qwerty keyboard letters and numbers are represented by the same key.
to get a number you have to hold the "function" button down while you press
the key. for example u=1, i=2, o=3..

on the keypress event how do change a U to a 1 if they forget to hold down
the funtion button? in this case it is for a textbox that is only ment for
digits so they push the U button they ment it to be a 1.


regards,
Jay
 
A

Alex Feinman [MVP]

In your KeyPress handler do something along these lines:

if ( e.KeyChar == 'q' )
{
PostMessage(hWnd, WM_CHAR, (int)Keys.D1, 1);
e.Handled = true;
}

where hWnd is a handle of the edit control.
This can be neatly wrapped in a class that has two string properties,
providing a substitution between characters
 

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