【发布时间】:2011-02-03 02:25:26
【问题描述】:
如何在winforms中设置输入密码的文本框?如果大写锁定打开,我还想显示“大写锁定已打开”弹出窗口。
我想要类似的东西
<input type="password" /> 在 HTML 中。
【问题讨论】:
如何在winforms中设置输入密码的文本框?如果大写锁定打开,我还想显示“大写锁定已打开”弹出窗口。
我想要类似的东西
<input type="password" /> 在 HTML 中。
【问题讨论】:
解决问题的最佳方法是将UseSystemPasswordChar 属性设置为true。然后,当用户输入该字段并且 Caps-Lock 处于打开状态时(至少对于 Vista 和 Windows 7),将显示 Caps-lock 消息。
另一种方法是将PasswordChar 属性设置为字符值(例如*)。这也会触发自动 Caps-Lock 处理。
【讨论】:
设置密码输入文本框:
textBox1.PasswordChar = '*';
您还可以在设计时通过编辑文本框的属性来更改此属性。
显示“Capslock 是否开启”:
using System;
using System.Windows.Forms;
//...
if (Control.IsKeyLocked(Keys.CapsLock)) {
MessageBox.Show("The Caps Lock key is ON.");
}
【讨论】:
PasswordChar 或 UseSystemPasswordChar - 至少在 Windows 7 和 Vista 上 - 如果字段获得焦点,则会自动处理 Caps-Lock。
要使PasswordChar 改用● 字符:
passwordTextBox.PasswordChar = '\u25CF';
【讨论】:
只需将TextBox.PasswordChar 属性设置为'*'。
【讨论】:
只需设置文本框的属性为
PasswordChar 并将 * 设置为属性
的文本框。这将适用于密码。
passwordtextbox.PasswordChar = '*';
其中passwordtextbox 是文本框名称。
【讨论】:
private void cbShowHide_CheckedChanged(object sender, EventArgs e)
{
if (cbShowHide.Checked)
{
txtPin.UseSystemPasswordChar = PasswordPropertyTextAttribute.No.Password;
}
else
{
//Hides Textbox password
txtPin.UseSystemPasswordChar = PasswordPropertyTextAttribute.Yes.Password;
}
}
复制此代码以使用复选框显示和隐藏您的文本框
【讨论】:
你可以像这样使用“txtpassword.PasswordChar = '•';”
使用地点是……
namespace Library_Management_System
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
txtpassword.PasswordChar = '•';
【讨论】:
我知道完美的答案:
我更喜欢去 windows 字符映射并找到像●这样的完美隐藏。
example:TextBox2.PasswordChar = '●';
【讨论】: