Export (0) Print
Expand All

TextBoxBase.Modified Property

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.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public bool Modified { get; set; }
/** @property */
public boolean get_Modified ()

/** @property */
public void set_Modified (boolean value)

public function get Modified () : boolean

public function set Modified (value : boolean)

Not applicable.

Property Value

true if the control's contents have been modified; otherwise, false. The default is false.

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.

If you change the Text property programmatically, the Modified property reverts to false. This does not raise the ModifiedChanged event.

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. 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. If the contents have changed, the Modified property is set to true. Otherwise, it is reset to false. This 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.Equals(textBox1.get_Text()))) {
        // Set the Modified property to true to reflect the change.
        textBox1.set_Modified(true);
    }
    else {
        // Contents of textBox1 have not changed,
        // reset the Modified property.
        textBox1.set_Modified(false);
    }
} //TextBox1_TextChanged 

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft