IF/Then "printable character" KeyPress

  • Thread starter Thread starter Keith Smith
  • Start date Start date
K

Keith Smith

How can I say "If e is equal to a printable character (as opposed to Insert,
Del, Home, PageUp, PageDown, etc) then x=1"?

Something like...

if (e.KeyChar==PrintableCharacters)
{
x=1;
}
 
Brian Keating said:
if (e.KeyChar=='Q')

Is this the only way?

if (e.KeyChar=='A' or e.KeyChar=='a'; e.KeyChar=='B'; e.KeyChar=='b';
.....etc

If so then what a pain!
 
Assuming that's what you needed to do, it'd be far simpler to write:
if((e.KeyChar >= 'A' && e.KeyChar <= 'Z')) || (e.KeyChar >= 'a' && e.KeyChar
<= 'z') ...)

But I think using if(!e.KeyChar.IsControl()) as suggested by Joakim would
probably fit your needs.
 
great idea thanks.


Sean Hederman said:
Assuming that's what you needed to do, it'd be far simpler to write:
if((e.KeyChar >= 'A' && e.KeyChar <= 'Z')) || (e.KeyChar >= 'a' &&
e.KeyChar <= 'z') ...)

But I think using if(!e.KeyChar.IsControl()) as suggested by Joakim would
probably fit your needs.
 
How can I say "If e is equal to a printable character (as opposed to
Insert, Del, Home, PageUp, PageDown, etc) then x=1"?

Something like...

if (e.KeyChar==PrintableCharacters)
{
x=1;
}

You could get the ascii-code for the char, and then check if it's within at
printable range ?

/René
 

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