e.KeyCode in KeyDown

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why does the following code

char l_ch = Convert.ToChar(
e.KeyCode);

give me the value 226 ('â') and not 60 ('<') when I press '<' ?
What am I doing wrong? I have also tried

char l_ch = Convert.ToChar(
e.KeyCode,
CultureInfo.InvariantCulture);
 
I'm interested in the answer to the question I posted, but what I really want
to do is to make sure that my text box cannot contain certain characters like
< > | * ? : \ / ". In ASP .NET there is a special control for this, called a
validator, but I cannot find a validator like that in my toolbox. Any
suggestions?
 
You can take a look at the same pattern used by Windows controls these have
virtual method called IsInputChar() en IsInputKey() where you evaluate the
key pressed and return either true or false. But mostly these kinds of
things are implemented using a regular expression.

Gabriel
 

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

Back
Top