TextBox.CharacterCasing 属性
获取或设置 TextBox 控件是否在字符键入时修改其大小写格式。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Public Property CharacterCasing As CharacterCasing
用法
Dim instance As TextBox
Dim value As CharacterCasing
value = instance.CharacterCasing
instance.CharacterCasing = value
public CharacterCasing CharacterCasing { get; set; }
public:
property CharacterCasing CharacterCasing {
CharacterCasing get ();
void set (CharacterCasing value);
}
/** @property */
public CharacterCasing get_CharacterCasing ()
/** @property */
public void set_CharacterCasing (CharacterCasing value)
public function get CharacterCasing () : CharacterCasing
public function set CharacterCasing (value : CharacterCasing)
属性值
CharacterCasing 枚举值中的一个值,它指定 TextBox 控件是否修改字符的大小写格式。默认为 CharacterCasing.Normal。
异常
异常类型 | 条件 |
---|---|
分配给该属性的值不在该枚举的有效值范围内。 |
备注
可以使用 CharacterCasing 属性根据应用程序的要求更改字符的大小写。例如,您可以将作为密码输入到 TextBox 控件中的所有字符更改为大写或小写,以实现某种密码策略。
示例
下面的代码示例创建用于接受密码的 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
请参见
参考
TextBox 类
TextBox 成员
System.Windows.Forms 命名空间
CharacterCasing 枚举