简体   繁体   中英

How to enter a special character as a password character in C#

How do I enter a unicode character (it needs to be the equivalent of ascii character 254, a solid square centered box) as the password character in a textbox?

I need to do this in code, for example textbox.passwordchar = ????????

Thanks,

The same way you enter any other character.
C# source files can contain Unicode characters in identifiers and strings.

You can also use the escape sequence "\\uxxxx" to use a Unicode character by (hex) codepoint.

Use the TestBox.PasswordChar property. Assuming you want UNICODE character BLACK SQUARE (U+25A0) , either do:

yourTextBox.PasswordChar = '■';

Or:

yourTextBox.PasswordChar = '\u25a0';
tb.PasswordChar = (char)254;

我相信您应该能够只分配一个恒定的Unicode字符,如本MSDN文章中所述 ...

this.tePassword.Properties.PasswordChar = (char)254; results in a character that looks similar to ab - it's definitely not ascii 254.

textBox_Name.PasswordChar='■';

When you want to use any of the unicode char simply Press ALT & then ascii value of that key while pressing ALT key

eg

■ = ALT+254

♪ = ALT+269

A = ALT+65

a = ALT+97

NOTE: numeric keys must be pressed from NumPad

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM