简体   繁体   English

如何创建一个持续更新的文本框,以在添加项目后立即显示更新的小计?

[英]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.

相关问题 如何检查某个字符串的文本文件并在添加该字符串时通知? - How do I check a text file for a certain string and notify when that string has been added? 将文本添加到文本框后添加新行 - Add a new line after text has been added to a textbox 即使我清除具有相同键的项目也已添加错误 - An item with the same key has already been added error even when i clear 类实例化后,如何创建公共变量? - How do I create public variables after the class has been instantiated? 具有相同键的项目已被添加。 (Ajaxcontroltoolkit) - An item with the same key has already been added. (Ajaxcontroltoolkit) 具有相同键的项目已添加到词典中 - An item with the same key has already been added to dictionary 已添加具有相同键的项目 - csvreader.fieldcount - An item with the same key has already been added - csvreader.fieldcount 如何在对象的构造函数完成后立即触发事件? - How do I get an event to fire as soon as an object's constructor has finished? 如何在TextBox填写完毕后几秒钟自动提交表单 - How to automatically submit form seconds after TextBox has been filled VB.NET DataGridView“在使用唯一索引的情况下,已经添加了具有相同键的项。” - VB.NET DataGridView “An item with the same key has already been added.” while using a unique index
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM