Language

TextBoxBase.Modified プロパティ

定義

コントロールが作成されたとき、またはその内容が最後に設定された後に、テキスト ボックス コントロールがユーザーによって変更されたことを示す値を取得または設定します。

public:
 property bool Modified { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool Modified { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Modified : bool with get, set
Public Property Modified As Boolean

プロパティ値

true コントロールの内容が変更されている場合。それ以外の場合は false。 既定値は false です。

属性

例

次のコード例では、派生クラスであるTextChangedのTextBox イベントを使用して、コントロールがデータでいっぱいになった後にTextBox コントロールの内容が変更されたかどうかを判断します。 この例では、文字列を使用してコントロールの元の内容を格納し、 TextBox の内容と比較して、内容が変更されたかどうかを判断します。 内容が変更された場合、 Modified プロパティは true に設定されます。 それ以外の場合は、 falseにリセットされます。 この例では、TextBoxという名前のtextBox1 コントロールが作成され、String コントロールの元のテキストを格納するために originalText という名前のTextBox変数が作成されている必要があります。

private:
   void TextBox1_TextChanged( Object^ sender, EventArgs^ e )
   {
      /* Check to see if the change made does not return the
         control to its original state. */
      if ( originalText != textBox1->Text )
      {
         // Set the Modified property to true to reflect the change.
         textBox1->Modified = true;
      }
      else
      {
         // Contents of textBox1 have not changed, reset the Modified property.
         textBox1->Modified = false;
      }
   }
private void TextBox1_TextChanged(object sender, EventArgs e)
 {
    /* Check to see if the change made does not return the
       control to its original state. */
    if (originalText != textBox1.Text)
       // Set the Modified property to true to reflect the change.
       textBox1.Modified = true;
    else
       // Contents of textBox1 have not changed, reset the Modified property.
       textBox1.Modified = false;
 }
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
    ' Check to see if the change made does not return the
    ' control to its original state. 
    If originalText <> textBox1.Text Then
        ' Set the Modified property to true to reflect the change.
        textBox1.Modified = True
        ' Contents of textBox1 have not changed, reset the Modified property.
    Else
        textBox1.Modified = False
    End If
End Sub

注釈

このプロパティを使用すると、ユーザーがテキスト ボックス コントロールの内容を変更したかどうかを確認できます。 このプロパティをコードで設定して、アプリケーションによってテキスト ボックス コントロールに変更が加えられたことを示すこともできます。 このプロパティは、検証およびデータ保存メソッドで使用して、変更された内容を検証または保存できるように、テキスト ボックス コントロールで変更が行われたかどうかを判断できます。

Text プロパティをプログラムで変更すると、Modified プロパティはfalseに戻ります。 これにより、 ModifiedChanged イベントは発生しません。

適用対象