[英]How do I create a continuously updating Textbox that displays an updated subtotal as soon as an item has been added?
I want to create a textbox that, when a new value is added to a variable (for example: Price1
is assigned the value of 3.5), a textbox with the code 我想创建一个文本框,当将新值添加到变量时(例如: Price1
的值分配为3.5),文本框将包含以下代码
CheckP7_TextChanged(sender As Object, e As EventArgs) Handles checkP7.TextChanged
Dim subTotal As Double
subTotal = (price1 * quant1 * taxRate) + (price2 + quant2 + taxRate)
End Sub
would calculate the subtotal continuously until the user presses the checkout button. 会持续计算小计,直到用户按下结帐按钮。 How would I go about doing this? 我将如何去做呢?
As far as I've tried, I can only get the textboxes to update when clicking a button saying "Calculate". 据我所试,我只能在单击“计算”按钮时更新文本框。
I expect the output to just continuously update the textbox with the current subtotal until the user hits either "Calculate" or "Checkout". 我希望输出只是用当前的小计持续更新文本框,直到用户点击“计算”或“签出”为止。
(eg I have 2 hotdogs in the cart, each at a price of $2.5 . The subtotal shows $5 [before taxes], and I add a hamburger at $3.5 each. The subtotal is immediately updated to show the new price [$8.5])" (例如,我的购物车中有2个热狗,每个热狗的价格为2.5美元。小计显示为5美元(税前),我添加一个汉堡包的价格为3.5美元。小计立即更新为显示新价格[8.5美元])”
As far as I can tell by interpreting your current implementation, you are trying to achieve a real-time calculation/display on Winform/WPF -- correct me if i am wrong... 据我通过解释您当前的实现所知,您正在尝试在Winform / WPF上实现实时计算/显示-如果我错了请指正...
In general, you can achieve the real time calculation/display by handling the various events of the controls, but i would advise you to try create your won view/business models that implement INotifyPropertyChanged interface: * if any of the properties (like price, quantity, etc.) is changed, then raise a property changed event * and also raise a property changed event for the property of "Total" 通常,您可以通过处理控件的各种事件来实现实时计算/显示,但是我建议您尝试创建实现INotifyPropertyChanged接口的赢取视图/业务模型:*如果有任何属性(例如价格,数量等),然后引发属性更改事件*并为“总计”属性引发属性更改事件
and in your frontend, just bind all the fields to the various controls, with two way bindings. 在您的前端,只需通过两种方式将所有字段绑定到各种控件即可。
so all the input at frontend will be taken into the object and causes a chain of updating, which would eventually result in the display of the total/sub-totals.. 因此前端的所有输入都将被带到对象中,并导致更新链,最终将导致显示总计/小计。
i believe you could find plenty of examples online... 我相信您可以在网上找到很多例子...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.