Share via


TextBoxBase.Modified Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan bahwa kontrol kotak teks telah dimodifikasi oleh pengguna sejak kontrol dibuat atau kontennya terakhir diatur.

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

Nilai Properti

true jika konten kontrol telah dimodifikasi; jika tidak, false. Default adalah false.

Atribut

Contoh

Contoh kode berikut menggunakan TextChanged peristiwa untuk TextBox, kelas turunan TextBox , untuk menentukan apakah konten kontrol telah berubah sejak kontrol diisi dengan data. Contohnya menggunakan string untuk menyimpan konten asli kontrol dan membandingkannya dengan konten TextBox untuk menentukan apakah konten telah berubah. Jika konten telah berubah, Modified properti diatur ke true. Jika tidak, reset ke false. Contoh ini mengharuskan TextBox kontrol bernama textBox1 telah dibuat dan variabel String bernama originalText telah dibuat untuk menyimpan teks asli untuk TextBox kontrol.

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

Keterangan

Anda dapat menggunakan properti ini untuk menentukan apakah pengguna telah mengubah konten kontrol kotak teks. Anda juga dapat mengatur properti ini dalam kode untuk menunjukkan bahwa perubahan dilakukan pada kontrol kotak teks oleh aplikasi. Properti ini dapat digunakan oleh metode validasi dan penyimpanan data untuk menentukan apakah perubahan dilakukan dalam kontrol kotak teks sehingga konten yang diubah dapat divalidasi atau disimpan.

Jika Anda mengubah Text properti secara terprogram, Modified properti kembali ke false. Ini tidak menaikkan ModifiedChanged peristiwa.

Berlaku untuk