methuselah
methuselah

Reputation: 13216

Checking what character has been "backspaced"

How would I determine the character which been backspaced and then play out the following conditions:

Code below:

    private void RemoveLast(TextBox tb)
    {
        if (tb.Text.Length > 0)
        {
            tb.Text = tb.Text.Remove(tb.Text.Length - 1, 1);
        }
    }

    private void btnback_Click(object sender, EventArgs e)
    {
        if (remainTxt.BackColor == Color.FromArgb(245, 244, 162))
        {
            RemoveLast(remainTxt);
        }
        else if (totalTxt.BackColor == Color.FromArgb(245, 244, 162))
        {
            RemoveLast(totalTxt);
        }
        else if (paidTxt.BackColor == Color.FromArgb(245, 244, 162))
        {
            RemoveLast(paidTxt);
        }
    }

Upvotes: 0

Views: 54

Answers (1)

Selman Genç
Selman Genç

Reputation: 101731

if (tb.Text.Length > 0)
{
   if(char.IsDigit(tb.Text[tb.Text.Length - 1]) count = 0;
   else 
   { 
       dotControl = false;
       count = 0;
   }
    tb.Text = tb.Text.Remove(tb.Text.Length - 1, 1);
}

By the way second count = 0 (in else statement) is redundant I guess,user can enter one digit after dot,so if he click back and delete one digit count will be zero.

Upvotes: 2

Related Questions