TextBox Modified and TextChanged : TextBox « GUI Windows Forms « C# / CSharp Tutorial






TextBox Modified and TextChanged
using System;
using System.Drawing;
using System.Windows.Forms;

public class TextBoxTextChanged : Form
{
  TextBox txt;
  string strOriginal;

  public TextBoxTextChanged()
  {
    Size = new Size(300, 375);
               
    txt = new TextBox();
    txt.Parent = this;
    txt.Text = "Enter text here.";
    txt.Size = new Size(ClientSize.Width - 20, ClientSize.Height - 100);
    txt.Location = new Point(10,10);
    txt.TextChanged += new System.EventHandler(txt_TextChanged);
    txt.Multiline = true;
    txt.BorderStyle = BorderStyle.Fixed3D;
    txt.ScrollBars = ScrollBars.Vertical;
    txt.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
    strOriginal = txt.Text;

  }

  static void Main() 
  {
    Application.Run(new TextBoxTextChanged());
  }

  private void txt_TextChanged(object sender, EventArgs e)
  {
    if (strOriginal == txt.Text)
      txt.Modified = false;
    else
      txt.Modified = true;

    if (txt.Modified)
      MessageBox.Show("changed");
    else
      MessageBox.Show("no change");
  }
}








23.17.TextBox
23.17.1.Get input value from TextBox and display it vis a messagebox
23.17.2.TextBox key pressed event
23.17.3.TextBox Modified and TextChangedTextBox Modified and TextChanged
23.17.4.TextBox: Multiline and BorderStyleTextBox: Multiline and BorderStyle
23.17.5.TextBox Keyevent handerTextBox Keyevent hander
23.17.6.TextBox cancel eventTextBox cancel event
23.17.7.Count lines in the TextBox and read text in TextBox line by lineCount lines in the TextBox and read text in TextBox line by line
23.17.8.TextBox selectionTextBox selection
23.17.9.TextBox validationTextBox validation
23.17.10.Add ContextMenu to TextBoxAdd ContextMenu to TextBox
23.17.11.Use Regular Expression to Check the input for a TextBoxUse Regular Expression to Check the input for a TextBox
23.17.12.Multiline TextBoxMultiline TextBox
23.17.13.Simple Editor