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コントロールが作成され、コントロールStringの元のテキストTextBoxを格納するために という名前originalTextの変数が作成されている必要textBox1があります。

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 変更すると、 プロパティは Modifiedfalse戻ります。 これにより、イベントは ModifiedChanged 発生しません。

適用対象