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 事件。

適用於