isprint

  • Thread starter Thread starter Jaga
  • Start date Start date
J

Jaga

1.)
I am using C#. Is there any similar function to isprint in C?

2.)
If I trap the event OnKeyDown in a Control, I become a
System.Windows.Forms.KeyEventArgs.
How can I determine whether the key in the KeyEventArgs a printable char is?

Thanks in advance

Jaga
 
I think you'll find that Char.IsControl() will do what you're after.

public static void Main() {
char c = '\t'; \\ Tab character

Console.WriteLine(Char.IsControl(c));
}
 
You could also use the Char.GetUnicodeCategory function();

public static void Main() {
char c = '\t';

Console.WriteLine("Character is printable: {0}",
Char.GetUnicodeCategory(c) != UnicodeCategory.Control);
}
 
Thank you Ed.
It means all the character, which is NOT IsControl is a printable
character?

I 'd like to test it. Does anybody knows how can I convert
System.WindowsForms.Keys.Left in a char?

Thanks

Jaga
 
Jaga,

This keystroke does not produce a character at all - I am pretty sure the
KeyPress event either is not raised for this keystroke, or the Char property
value in the passed KeyPressedEventArgs instance does not contain a valid
value.

To summarize, you should distinguish characters and keystrokes. Not every
keystroke can produce a character, and not every Unicode character can be
produced by a keystroke given current keyboard layout and input locale
(except for tricks like Alt followed by digit keys on the numeric
("calculator-layout") keyboard pad).
 
Thank you Dmitriy.
You are right, the KeyPress event is raised only if the keystroke a
printable character ist.
But it is too late for me. I must already trap the event KeyDown or the
PreProcessMessage.
How can I determine whether the key in the KeyEventArgs of the KeyDown event
a printable char is? The framework can do it, it raises the KeyPress event
only for such characters.


Jaga



Dmitriy Lapshin said:
Jaga,

This keystroke does not produce a character at all - I am pretty sure the
KeyPress event either is not raised for this keystroke, or the Char property
value in the passed KeyPressedEventArgs instance does not contain a valid
value.

To summarize, you should distinguish characters and keystrokes. Not every
keystroke can produce a character, and not every Unicode character can be
produced by a keystroke given current keyboard layout and input locale
(except for tricks like Alt followed by digit keys on the numeric
("calculator-layout") keyboard pad).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Jaga said:
Thank you Ed.
It means all the character, which is NOT IsControl is a printable
character?

I 'd like to test it. Does anybody knows how can I convert
System.WindowsForms.Keys.Left in a char?

Thanks

Jaga




im Newsbeitrag news:[email protected]...
 
Back
Top