Which passwordchar shows a black dot (•) in a winforms textbox using code?
Solution 1
http://blog.billsdon.com/2011/04/dot-password-character-c/ suggests '\u25CF';
Or try copy pasting this •
Solution 2
(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.
Solution 3
You need to look into using the PasswordBox
control and setting the PasswordChar
as *
.
Example:
textBox1.PasswordChar = '*'; // Set a text box for password input
Solution 4
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")
.
Cocoa Dev
Updated on June 14, 2022Comments
-
Cocoa Dev almost 2 years
Possible Duplicate:
Which passwordchar shows a black dot (•) in a winforms textbox?
Unicode encoding for string literals in C++11I want to use code to reveal the password or make it a dot like •
textBoxNewPassword.PasswordChar = (char)0149;
How can I achieve this?