次の方法で共有


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 プロパティよりも優先されます。UseSystemPasswordChartrue に設定されている場合、既定のシステムのパスワード文字が使用され、PasswordChar で設定された文字は無視されます。

Multiline プロパティが true に設定されている場合は、PasswordChar プロパティを設定しても外観に変更はありません。PasswordChar プロパティが true に設定されている場合は、Multiline プロパティが truefalse のどちらに設定されている場合でも、コントロールでキーボードを使用した切り取り、コピー、および貼り付けは実行できません。

注意

日本語版のオペレーティング システムでは、Multiline プロパティが truefalse かに関係なく、PasswordChar が適用されます。その他のオペレーティング システムでは、Multilinefalse の場合にだけ PasswordChar が適用されます。

メモ重要 :

PasswordCharUseSystemPasswordChar、または ReadOnlytrue であるために、TextBox がパスワード モードの場合は、TextBox は制限モードです。このモードでは、ImeMode が無効になりますが、現在の ImeMode はキャッシュされるため、TextBox の制限が解除された場合に、これを元に戻すことができます。たとえば、ReadOnly を切り替えた場合などです。コントロールが制限モードの場合は、ImeMode がシャドウされます。デザイナから見た場合、表示された ImeMode 値が実際の値です。

使用例

パスワードを受け取るために使用される TextBox コントロールを作成するコード例を次に示します。この例では、CharacterCasing プロパティを使用して、入力されたすべての文字を大文字に変更します。また、MaxLength プロパティを使用して、パスワード長を 8 文字に制限します。この例では、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

参照

関連項目

TextBox クラス
TextBox メンバ
System.Windows.Forms 名前空間