简体   繁体   中英

How to multiply two textbox values and display answer to third in c#?

In my program have 3 textboxes. which are for subtotal,discount and grand total.Subtotal value will display after some calculations and I should type discount manually.Then after type discount value in textbox i need to display grandtotal value automatically in grandtotal textbox.How to do this.I try this

txtgrandtotal.Text = (Convert.ToDouble(txtdiscount.Text) * Convert.ToDouble(txtsubtotal.Text)).ToString();

But it didn't work for textchange event

You can do this with the TextChange Event on the TextBox txtdiscount control.

Once you added the event you can do your calculation like this:

private void txtdiscount_TextChanged(object sender, EventArgs e)
{
    txtgrandtotal.Text = (Convert.ToDouble(txtdiscount.Text) * Convert.ToDouble(txtsubtotal.Text)).ToString();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM