如何计算两个文本框的值
hi
我有3个文本框txtamont.text,txtTotalAmount.text和txtDue.text Simultaneouly.当我在txtamont.text中输入10000且Totla金额为15000时,如何在txtDue.text中自动显示到期金额,请告诉我任何人plz
hi
I have 3 textboxes txtamont.text , txtTotalAmount.text and txtDue.text Simultaneouly .When i have enter in txtamont.text 10000 and Totla amount is 15000 then in how to display Due amount in txtDue.text automatically remaining amount please tell me anyone plz
您可以使用TextChanged事件进行计算,检查 txtamont.text 和 txtTotalAmount.text 不是空白,然后将其解析为数字
然后设置
Hi,
You can use TextChanged event to calculate, check txtamont.text and txtTotalAmount.text are not blank and parse them they are numeric
then Set
txtDue.Text =Convert.ToDecimal(txtTotalAmount.Text) -Convert.ToDecimal(txtamont.Text)
否则,您可以创建一个类CalDueAmt,在其中公开两个属性
在Text Chnage上,只需设置TotalAmt和Amt即可获取计算值
or else you can create a class CalDueAmt where you expose two property
On Text Chnage just Set TotalAmt and Amt get calculated value
class CalDueAmt
{
private decimal _TotalAmt;
public decimal TotalAmt { get { return _TotalAmt;}
set { _TotalAmt=value; Calculate();}
private decimal _Amt;
public decimal Amt { get { return _Amt;}
set { _Amt=value; Calculate();}
private void Calculate()
{
txtDue.Text=_TotalAmt-_Amt;
}
}
您应该将其用作That的嵌套类,在第二个文本框的文本更改事件中,该类需要进行计算.
you should use this as a nested class of That from where calculation required .
写计算.
txtDue.Text = Convert.ToDecimal(txtTotalAmount.Text)-Convert.ToDecimal(txtamont.Text)
in the text changed event of the second text box. write the calculation.
txtDue.Text =Convert.ToDecimal(txtTotalAmount.Text) -Convert.ToDecimal(txtamont.Text)