我的表单中有一些文本框。我编写了休假事件的代码以自动添加 0.00。我编写了将两个文本框值添加到第三个的代码
try
{
decimal netVal = 0;
decimal.TryParse(txtNetValue.Text, out netVal);
decimal disc2 = 0;
decimal.TryParse(txtDisc2.Text, out disc2);
decimal tax1 = 0;
decimal.TryParse(txtTax1.Text, out tax1);
decimal tax = netVal - disc2;
string strtax = ((tax / 100) * tax1).ToString();
txtTax2.Text = strtax.Substring(0, strtax.IndexOf(".") + 3);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
在这种情况下,当我单击新按钮以清除所有控件时,我得到一个例外,即Index and length must refer to a location within the string. Parameter name: length
.