每當用戶按下上一個空文本字段的退格鍵時,出現以下錯誤消息:防止當用戶按下退格按鈕時文本字段是空的錯誤消息
類型「System.ArgumentOutOfRangeException」的未處理的異常在mscorlib.dll中發生了 。附加信息:StartIndex不能爲 小於零。
如何讓它忽略退格鍵按下,如果文本字段爲空。
private void btnback_Click(object sender, EventArgs e)
{
if (remainTxt.BackColor == Color.FromArgb(245, 244, 162))
{
remainTxt.Text = remainTxt.Text.Remove(remainTxt.Text.Length - 1, 1);
}
else if (totalTxt.BackColor == Color.FromArgb(245, 244, 162))
{
totalTxt.Text = totalTxt.Text.Remove(totalTxt.Text.Length - 1, 1);
}
else if (paidTxt.BackColor == Color.FromArgb(245, 244, 162))
{
paidTxt.Text = paidTxt.Text.Remove(paidTxt.Text.Length - 1, 1);
}
}