2

Possible Duplicate:
Which passwordchar shows a black dot (•) in a winforms textbox?
Unicode encoding for string literals in C++11

I want to use code to reveal the password or make it a dot like •

textBoxNewPassword.PasswordChar = (char)0149;

How can I achieve this?

Community
  • 1
  • 1
Cocoa Dev
  • 9,361
  • 31
  • 109
  • 177

5 Answers5

7

http://blog.billsdon.com/2011/04/dot-password-character-c/ suggests '\u25CF';

Or try copy pasting this •

MikeB
  • 2,402
  • 1
  • 15
  • 24
7

(not exactly an answer to your question, but still)

You can also use the UseSystemPasswordChar property to select the default password character of the system:

textBoxNewPassword.UseSystemPasswordChar = true;

Often mapped to the dot, and always creating a consistent user experience.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
1

You need to look into using the PasswordBox control and setting the PasswordChar as *.

Example:

textBox1.PasswordChar = '*'; // Set a text box for password input
dsgriffin
  • 66,495
  • 17
  • 137
  • 137
1

Wikipedia has a table of similar symbols.

In C#, to make a char literal corresponding to U+2022 (for example) use '\u2022'. (It's also fine to cast an integer literal as you do in your question, (char)8226)


Late addition. The reason why your original approach was unsuccessful, is that the value 149 you had is not a Unicode code point. Instead it comes from Windows-1252, and Windows-1252 is not a subset of Unicode. In Unicode, decimal 149 means the C1 control code "Message Waiting".

You could translate from Windows-1252 with:

textBoxNewPassword.PasswordChar = 
  Encoding.GetEncoding("Windows-1252").GetString(new byte[] { 149, })[0];

but it is easier to use the Unicode value directly of course.


In newer versions of .NET, you need to call:

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

before you can use something like Encoding.GetEncoding("Windows-1252").

Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
0
textBoxNewPassword.PasswordChar = '\u25CF';
chridam
  • 100,957
  • 23
  • 236
  • 235