Reputation: 13216
How would I determine the character which been backspaced and then play out the following conditions:
count=0
dotControl=false
and count=0
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
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