如何使用c#将文本显示为隐藏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/351296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show a text as hidden using c#
提问by Layla
I am developping in C#. I need to capture a password written inside a Text Box, but would like to not show the password that is being typed, showing instead **** or any other character to hide the password.
我正在用 C# 开发。我需要捕获写在文本框中的密码,但不想显示正在键入的密码,而是显示 **** 或任何其他字符以隐藏密码。
How can I do that? I'm sure it's by modifying an attribute, but can't find which one.
我怎样才能做到这一点?我确定它是通过修改一个属性,但找不到哪个。
采纳答案by Jimmy
http://msdn.microsoft.com/en-us/library/d3223ht2.aspx
http://msdn.microsoft.com/en-us/library/d3223ht2.aspx
set the PasswordChar property of the textbox
设置文本框的 PasswordChar 属性
回答by Patrik Svensson
There is a property on the TextBox class called "UseSystemPasswordChar" (assuming winforms) that let you do this.
TextBox 类中有一个名为“UseSystemPasswordChar”(假设为 winform)的属性,可让您执行此操作。
回答by Rob Kennedy
Set the PasswordChar
property.
回答by grepsedawk
To use your own custom character: http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.passwordchar.aspx
要使用您自己的自定义字符:http: //msdn.microsoft.com/en-us/library/system.windows.forms.textbox.passwordchar.aspx
To use the system default character: http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.usesystempasswordchar.aspx
使用系统默认字符:http: //msdn.microsoft.com/en-us/library/system.windows.forms.textbox.usesystempasswordchar.aspx
textBox1.UseSystemPasswordChar = true;
//or
textBox1.PasswordChar = '%';