YKhaing
YKhaing

Reputation: 123

How to display special characters - knowing its alt code

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

Answers (2)

roman
roman

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

JleruOHeP
JleruOHeP

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

Related Questions