Reputation: 123
I want to know how to display some special characters from character map (using with Alt) when user type some key.
For example: display ¥
(Alt+0165) when type \
, display §
(Alt+0167) when type [
.
I know that the following code display z
if user type a
. But I don't know for characters with Alt key.
private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 'a')
e.KeyChar = 'z';
}
Thanks in advance.
Upvotes: 2
Views: 4042
Reputation: 117410
you can also try
private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '[')
e.KeyChar = (char)167;
else if (e.KeyChar == '\\')
e.KeyChar = (char)165;
}
Upvotes: 1
Reputation: 10376
I think straight forward way must work correct:
private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '[')
e.KeyChar = '§';
else if (e.KeyChar == '\\')
e.KeyChar = '¥';
}
Just type those chars with Alt in Visual studio!
Upvotes: 1