TextBoxBase.Modified 属性

定义

获取或设置一个值,该值指示自创建文本框控件或上次设置该控件的内容后,用户修改了该控件。Gets or sets a value that indicates that the text box control has been modified by the user since the control was created or its contents were last set.

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

属性值

Boolean

如果控件的内容被修改了,则为 true,否则为 falsetrue if the control's contents have been modified; otherwise, false. 默认值为 falseThe default is false.

属性

示例

下面的代码示例使用 TextChanged 派生类的事件 TextBox ,以确定控件的内容在 TextBox 使用数据填充后是否发生了更改。The following code example uses the TextChanged event for a TextBox, a derived class, to determine if the contents of the TextBox control have changed since the control was filled with data. 该示例使用字符串来存储控件的原始内容,并将其与的内容进行比较, TextBox 以确定内容是否已更改。The example uses a string to store the original contents of the control and compares it against the contents of the TextBox to determine if the contents have changed. 如果内容已更改,则将 Modified 属性设置为 trueIf the contents have changed, the Modified property is set to true. 否则,它将重置为 falseOtherwise, it is reset to false. 此示例需要创建一个 TextBox 名为的控件 textBox1 ,并且已创建一个名为的 String 变量 originalText 来存储控件的原始文本 TextBoxThis example requires that a TextBox control named textBox1 has been created and that a String variable named originalText has been created to store the original text for the TextBox control.

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

注解

您可以使用此属性来确定用户是否修改了文本框控件的内容。You can use this property to determine if the user has modified the contents of the text box control. 你还可以在代码中设置此属性,以指示应用程序对文本框控件进行了更改。You can also set this property in code to indicate that changes were made to the text box control by the application. 此属性可由验证和数据保存方法用来确定是否已在文本框控件中进行了更改,以便可以验证或保存更改的内容。This property can be used by validation and data-saving methods to determine if changes were made in a text box control so the changed contents can be validated or saved.

如果 Text 以编程方式更改属性,该 Modified 属性将还原为 falseIf you change the Text property programmatically, the Modified property reverts to false. 这不会引发 ModifiedChanged 事件。This does not raise the ModifiedChanged event.

适用于