如何在 C# 中将两个文本框值相乘并显示第三个值的答案?
How to multiply two textbox values and display answer to third in c#?
在我的程序中有 3 个文本框。用于小计、折扣和总计 total.Subtotal 值将在一些计算后显示,我应该在文本框中键入折扣值后输入折扣 manually.Then 我需要在总计 textbox.How 中自动显示总计值this.I 试试这个
txtgrandtotal.Text = (Convert.ToDouble(txtdiscount.Text) * Convert.ToDouble(txtsubtotal.Text)).ToString();
但它对 textchange 事件不起作用
您可以使用 TextBox txtdiscount
控件上的 TextChange 事件来完成此操作。
添加事件后,您可以像这样进行计算:
private void txtdiscount_TextChanged(object sender, EventArgs e)
{
txtgrandtotal.Text = (Convert.ToDouble(txtdiscount.Text) * Convert.ToDouble(txtsubtotal.Text)).ToString();
}
在我的程序中有 3 个文本框。用于小计、折扣和总计 total.Subtotal 值将在一些计算后显示,我应该在文本框中键入折扣值后输入折扣 manually.Then 我需要在总计 textbox.How 中自动显示总计值this.I 试试这个
txtgrandtotal.Text = (Convert.ToDouble(txtdiscount.Text) * Convert.ToDouble(txtsubtotal.Text)).ToString();
但它对 textchange 事件不起作用
您可以使用 TextBox txtdiscount
控件上的 TextChange 事件来完成此操作。
添加事件后,您可以像这样进行计算:
private void txtdiscount_TextChanged(object sender, EventArgs e)
{
txtgrandtotal.Text = (Convert.ToDouble(txtdiscount.Text) * Convert.ToDouble(txtsubtotal.Text)).ToString();
}