C# 密码字符在System.Windows.Forms.TextBox上不起作用

C# 密码字符在System.Windows.Forms.TextBox上不起作用,c#,winforms,textbox,passwords,maskedtextbox,C#,Winforms,Textbox,Passwords,Maskedtextbox,真的是这样 我正在使用VS2008 Express 所有示例都说只需设置PasswordChar,但没有任何内容被屏蔽 我还尝试将“UseSystemPasswordChar”设置为true。。不走运 // Set to no text. textBox1.Text = ""; // The password character is an asterisk. textBox1.PasswordChar = '*'; // The control will allo

真的是这样

我正在使用VS2008 Express

所有示例都说只需设置PasswordChar,但没有任何内容被屏蔽

我还尝试将“UseSystemPasswordChar”设置为true。。不走运

   // Set to no text.
   textBox1.Text = "";
   // The password character is an asterisk.
   textBox1.PasswordChar = '*';
   // The control will allow no more than 14 characters.
   textBox1.MaxLength = 14;
我之所以使用文本框,是因为我希望用户能够点击return并提交数据。重要的是要注意,我想我有MultiLine=true,这样我就可以捕获返回

我似乎无法用一个蒙面的文本框捕捉到回报。我只听到一声系统的哔哔声


解决这两个问题对我来说都很好

使用maskedTextBox时,捕获按键并执行以下操作:

if ( e.KeyChar == 13) {
    /* This is the enter key. Do stuff. */
}

如果读取的是“如果多行属性设置为true,则设置PasswordChar属性没有视觉效果。”

UseSystemPasswordChar在多行设置为true时不起作用。即使Multiline=false,标准Windows窗体文本框也接受返回


解决方案:设置Multiline=False,并在表单上设置一个按钮以使用AcceptButton属性,或在文本框的“KeyPress”事件中捕获返回/回车键。

您可能还想注意,您可以使用表单上设置了AcceptButton属性的按钮在回车时提交该按钮: