TextBox.PasswordChar 属性
获取或设置字符,该字符用于屏蔽单行 TextBox 控件中的密码字符。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<LocalizableAttribute(True)> _
Public Property PasswordChar As Char
用法
Dim instance As TextBox
Dim value As Char
value = instance.PasswordChar
instance.PasswordChar = value
[LocalizableAttribute(true)]
public char PasswordChar { get; set; }
[LocalizableAttribute(true)]
public:
property wchar_t PasswordChar {
wchar_t get ();
void set (wchar_t value);
}
/** @property */
public char get_PasswordChar ()
/** @property */
public void set_PasswordChar (char value)
public function get PasswordChar () : char
public function set PasswordChar (value : char)
属性值
用于屏蔽在单行 TextBox 控件中输入的字符的字符。如果不想让控件在字符键入时将它们屏蔽,请将此属性值设置为 0(字符值)。默认值等于 0(字符值)。
备注
UseSystemPasswordChar 属性的优先级高于 PasswordChar 属性。每当 UseSystemPasswordChar 设置为 true 时,将使用默认系统密码字符,并忽略由 PasswordChar 设置的任何字符。
如果将 Multiline 属性设置为 true,则设置 PasswordChar 属性不会产生任何视觉效果。如果将 PasswordChar 属性设置为 true,则不管将 Multiline 属性设置为 true 还是 false,均不能使用键盘在控件中执行剪切、复制和粘贴操作。
提示
在日文操作系统上,无论 Multiline 属性是 true 还是 false,PasswordChar 均适用。在其他操作系统上,只有当 Multiline 是 false 时 PasswordChar 才适用。
重要事项: |
---|
当因为 PasswordChar、UseSystemPasswordChar 或 ReadOnly 为 true 而使 TextBox 处于密码模式时,TextBox 处于受限模式。在此模式中,ImeMode 被禁用,但是当前 ImeMode 被缓存,因此在 TextBox 变为不受限时可以将其还原。切换 ReadOnly 是一种常见方案。当该控件处于受限模式时,ImeMode 被隐藏。从设计器的角度看,显示的 ImeMode 值是实际值。 |
示例
下面的代码示例创建用于接受密码的 TextBox 控件。此示例使用 CharacterCasing 属性将键入的所有字符更改为大写字符,并使用 MaxLength 属性将密码长度限制为八个字符。此示例还使用 TextAlign 属性使密码在 TextBox 控件中居中显示。
Public Sub CreateMyPasswordTextBox()
' Create an instance of the TextBox control.
Dim textBox1 As New TextBox()
' Set the maximum length of text in the control to eight.
textBox1.MaxLength = 8
' Assign the asterisk to be the password character.
textBox1.PasswordChar = "*"c
' Change all text entered to be lowercase.
textBox1.CharacterCasing = CharacterCasing.Lower
' Align the text in the center of the TextBox control.
textBox1.TextAlign = HorizontalAlignment.Center
End Sub
public void CreateMyPasswordTextBox()
{
// Create an instance of the TextBox control.
TextBox textBox1 = new TextBox();
// Set the maximum length of text in the control to eight.
textBox1.MaxLength = 8;
// Assign the asterisk to be the password character.
textBox1.PasswordChar = '*';
// Change all text entered to be lowercase.
textBox1.CharacterCasing = CharacterCasing.Lower;
// Align the text in the center of the TextBox control.
textBox1.TextAlign = HorizontalAlignment.Center;
}
public:
void CreateMyPasswordTextBox()
{
// Create an instance of the TextBox control.
TextBox^ textBox1 = gcnew TextBox;
// Set the maximum length of text in the control to eight.
textBox1->MaxLength = 8;
// Assign the asterisk to be the password character.
textBox1->PasswordChar = '*';
// Change all text entered to be lowercase.
textBox1->CharacterCasing = CharacterCasing::Lower;
// Align the text in the center of the TextBox control.
textBox1->TextAlign = HorizontalAlignment::Center;
}
public void CreateMyPasswordTextBox()
{
// Create an instance of the TextBox control.
TextBox textBox1 = new TextBox();
// Set the maximum length of text in the control to eight.
textBox1.set_MaxLength(8);
// Assign the asterisk to be the password character.
textBox1.set_PasswordChar('*');
// Change all text entered to be lowercase.
textBox1.set_CharacterCasing(CharacterCasing.Lower);
// Align the text in the center of the TextBox control.
textBox1.set_TextAlign(HorizontalAlignment.Center);
} //CreateMyPasswordTextBox
public function CreateMyPasswordTextBox()
{
// Create an instance of the TextBox control.
textBox1 = new TextBox();
// Set the maximum length of text in the control to eight.
textBox1.MaxLength = 8;
// Assign the asterisk to be the password character.
textBox1.PasswordChar = '*';
// Change all text entered to be lowercase.
textBox1.CharacterCasing = CharacterCasing.Lower;
// Align the text in the center of the TextBox control.
textBox1.TextAlign = HorizontalAlignment.Center;
}
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0