How to get old text and changed text of textbox on TextChanged event of textbox?

You need to store the old value. For example in a field or property in the same class.

private string LastFinalTrans { get; set; }

private void txtFinalTrans_TextChanged_1(object sender, EventArgs e)
{
    TextBox txt = (TextBox) sender;
    if(LastFinalTrans == txt.Text)
    {
        // ...
    }
    LastFinalTrans =  txt.Text;
}

Try creating a global variable and put your textbox text during GotFocus event and use it as Old Text during TextChanged event as like:

string OldText = string.Empty;
private void textBox1_GotFocus(object sender, EventArgs e)
{
   OldText = textBox1.Text;
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
   string newText = textBox1.Text;
   //Compare OldText and newText here
}

Hope this helps...

Tags:

C#

.Net