TextBoxBase.Modified 属性

获取或设置一个值,该值指示自创建文本框控件或上次设置该控件的内容后,用户修改了该控件。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property Modified As Boolean
用法
Dim instance As TextBoxBase
Dim value As Boolean

value = instance.Modified

instance.Modified = value
public bool Modified { get; set; }
public:
property bool Modified {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_Modified ()

/** @property */
public void set_Modified (boolean value)
public function get Modified () : boolean

public function set Modified (value : boolean)

属性值

如果控件的内容被修改了,则为 true,否则为 false。默认为 false

备注

可以使用此属性确定用户是否修改了文本框控件的内容。还可以在代码中设置此属性,指示是由应用程序更改了文本框控件。此属性可由验证和数据保存方法使用,以确定文本框控件是否被更改了,以便验证或保存所更改的内容。

示例

下面的代码示例使用派生类 TextBoxTextChanged 事件,确定自从在 TextBox 控件中填充数据后,该控件的内容是否发生了更改。该示例使用一个字符串存储控件的原始内容,并将它与 TextBox 的内容相比较,以确定内容是否发生了更改。如果内容已更改,则 Modified 属性将设置为 true。否则,将重新设置为 false。此示例要求已创建一个名为 textBox1TextBox 控件,并已创建一个名为 originalTextString 变量来存储 TextBox 控件的原始文本。

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
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 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 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

TextBoxBase 类
TextBoxBase 成员
System.Windows.Forms 命名空间