密码字符在 System.Windows.Forms.TextBox 上不起作用
确实如此..
我正在使用 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;
我使用文本框的原因是因为我希望用户能够按回车键并提交数据。 值得注意的是,我想我有 MultiLine = true,这样我就可以捕获返回值。
我似乎无法使用 maskedTextBox 捕获返回。 我听到的只是一声系统蜂鸣声。
任何一个的解决方案对我来说都很好!
Thats it really..
I am using VS2008 Express.
All the samples say just to set the PasswordChar, but nothing gets masked.
I also tried setting the "UseSystemPasswordChar" = true.. no luck..
// 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;
The reason I'm using a TextBox is because I want the user to be able to hit return and it submits the data. Its important to note I guess that I have MultiLine = true so that I can capture the return.
I can't seem to be able to capture a return with a maskedTextBox. All I get is a system beep.
a solution to either is fine for me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您阅读文档< /a> 表示“如果 Multiline 属性设置为 true,则设置 PasswordChar 属性没有视觉效果。”
If you read the documentation is says "If the Multiline property is set to true, setting the PasswordChar property has no visual effect."
当 Multiline 设置为 true 时,UseSystemPasswordChar 不起作用。 即使 Multiline = false,标准 Windows 窗体文本框也接受返回。
解决方案:设置 Multiline = False,并在窗体上设置一个按钮以使用 AcceptButton 属性,或捕获文本框的“KeyPress”事件中的 return/enter 键。
UseSystemPasswordChar doesn't function when Multiline is set to true. The standard Windows Forms textbox accepts returns even when Multiline = false.
Solution: Set Multiline = False, and set a button on your form to use the AcceptButton property, or capture the return/enter key in the "KeyPress" event of the textbox.
当使用 maskedTextBox 捕获按键并执行以下操作时:
When using a maskedTextBox capture the key press and do something like: