在我的程序中有3个文本框。这是小计,折扣和总total.Subtotal值将显示在一些计算后,用户应该输入折扣manually.Then后,在文本框中键入折扣值,它将自动显示总计值在总计textbox.For这我使用这样的文本更改事件
private void txtdiscount_TextChanged_1(object sender, EventArgs e)
{
txtgrandtotal.Text = (Convert.ToDouble(txtsubtotal.Text)-(Convert.ToDouble(txtdiscount.Text) * Convert.ToDouble(txtsubtotal.Text))).ToString("#,0.00");
}
在将数据插入数据库后,我需要清除这个事件可以这样做吗?我使用了textbox.text="";对于所有的文本框,除了txtgrandtotal没有清除(与txtdiscount_TextChanged_1事件冲突)。
发布于 2018-06-06 01:51:31
尝试将所有textBox文本设置为""
,并在txtsubtotal
和txtdiscount
不为空时仅计算txtgrandtotal
!
private void txtdiscount_TextChanged_1(object sender, EventArgs e)
{
if (txtsubtotal.Text == "" || txtdiscount.Text == "")
return;
txtgrandtotal.Text = (Convert.ToDouble(txtsubtotal.Text) - (Convert.ToDouble(txtdiscount.Text) * Convert.ToDouble(txtsubtotal.Text))).ToString("#,0.00");
}
https://stackoverflow.com/questions/50706110
复制相似问题