【发布时间】:2021-10-21 05:17:51
【问题描述】:
所以我在 VB 中创建了一个菜单表单,它要求用户从菜单中选择项目,然后使用价格来计算总数。 为此,我创建了 2 个列表,其中一个是主表单:
Dim menu As New List(Of MenuItem) From
{
New MenuItem With {.Name = "Burger", .Cost = 2.0 * txtburger.Text},
New MenuItem With {.Name = "wrap", .Cost = 2.0 * txtwrap.Text},
New MenuItem With {.Name = "Parmesan", .Cost = 2.5 * txtparmesan.Text},
New MenuItem With {.Name = "Stirfry", .Cost = 3.0 * txtstirfry.Text},
New MenuItem With {.Name = "pitta", .Cost = 2.5 * txtpitta.Text},
New MenuItem With {.Name = "bundle", .Cost = 6.0 * txtbundle.Text},
此列表使用“MenuItem”类在菜单中创建项目并设置它们的价格。
第二个列表在“订单”类中:
Public Property Items As List(Of MenuItem) = New List(Of MenuItem)
Public Sub AddItem(ByVal item As MenuItem)
Items.Add(item)
End Sub
此类使用“AddItem”方法将先前定义的完整菜单中的项目添加到此列表中。此处添加到此列表中的项目是用户在加载表单时将选择的项目。
但是如何在“订单”类中实例化一个对象,以便用户选择的项目从主表单添加到此列表中?每个项目旁边都有一个文本框,用于确定项目的数量。所以我必须为每个被选中的项目传递一个参数。 我不太确定该怎么做。
希望这一切都有意义,我做得对。
【问题讨论】:
标签: vb.net list forms class oop