user503920
user503920

Reputation: 11

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,

Upvotes: 1

Views: 1959

Answers (6)

Javed Akram
Javed Akram

Reputation: 15354

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

e.g.

■ = ALT+254

♪ = ALT+269

A = ALT+65

a = ALT+97

NOTE: numeric keys must be pressed from NumPad

Upvotes: 1

David
David

Reputation: 1058

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

Upvotes: 0

Frédéric Hamidi
Frédéric Hamidi

Reputation: 263117

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

yourTextBox.PasswordChar = '■';

Or:

yourTextBox.PasswordChar = '\u25a0';

Upvotes: 2

Dan J
Dan J

Reputation: 16718

I believe you should be able to just assign a constant Unicode character, as described in this MSDN article...

Upvotes: 0

Ben Voigt
Ben Voigt

Reputation: 283803

tb.PasswordChar = (char)254;

Upvotes: 0

SLaks
SLaks

Reputation: 888077

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.

Upvotes: 2

Related Questions