如何计算两个文本框的值 [英] how to calculate two textboxes values

查看:84
本文介绍了如何计算两个文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)


这篇关于如何计算两个文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆