我可以获取textbox_name text和listbox_order项目在另一行列表框上正确显示

发布于 2025-01-25 08:49:35 字数 312 浏览 4 评论 0原文

我有3个列表框,ListBox_Menu是单击按钮(主菜,饮料和侧面)首先显示项目的地方,然后添加项目以订购您从listbox_menu中选择您的项目,然后单击添加订单以订购它出现在listbox_order中。一旦准备好的客户订单就从那里开始,提交按钮将打印出客户名称(TextBox_name)和ListBox_order中的所有项目,并将其全部显示为一行。

我只是难以弄清楚如何做到这一点,如果有人可以提供帮助。

“

I have 3 list boxes, the listBox_menu is where the items are first displayed if buttons (entrees, drinks, and sides) are clicked, then to add the items to order you select your item from the listBox_menu and click add to order to have it appear in the listBox_order. From there once the customer order is ready to be made the submit button will print out the customers name (textBox_name) and all the items in the listBox_order, and display it all in one line.

I'm just having trouble figuring out how to do that, if anyone could please help.

Code

Design

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2025-02-01 08:49:35

首先定义两个全局变量,然后使用calculateTotAlcost函数(我定义了)。

我的答案已更新。

输出(在Visual Studio 2017.NET框架4.5.2中测试):

“

这些是我的代码:

    public Form1()
    {
        InitializeComponent();
        listBox_menu.SelectionMode = SelectionMode.MultiExtended;
    }
    double Cost = 0;
    string Order = null;
    public double CalculateTotalCost(object input, bool Total)
    {
        if (Total == true)
        {
            switch (input)
            {
                case "Salad":
                    Cost += 2500;
                    break;
                case "Rice":
                    Cost += 3000;
                    break;
                case "non-alcoholic beer":
                    Cost += 1000;
                    break;
                case "Water":
                    Cost += 200;
                    break;
                case "Ex1":
                    Cost += 2200;
                    break;
                default:
                    Cost += 2200;
                    break;
            }
        }
        else
        {
            switch (input)
            {
                case "Salad":
                    Cost -= 2500;
                    break;
                case "Rice":
                    Cost -= 3000;
                    break;
                case "non-alcoholic beer":
                    Cost -= 1000;
                    break;
                case "Water":
                    Cost -= 200;
                    break;
                case "Ex1":
                    Cost -= 2200;
                    break;
                default:
                    Cost -= 2200;
                    break;
            }
        }
        return Cost;
    }
    private void Entrees_Click(object sender, EventArgs e)
    {
        listBox_menu.Items.Clear();
        listBox_menu.Items.Add("Salad");
        listBox_menu.Items.Add("Rice");
    }
    private void Drinks_Click(object sender, EventArgs e)
    {
        listBox_menu.Items.Clear();
        listBox_menu.Items.Add("non-alcoholic beer");
        listBox_menu.Items.Add("Water");
    }
    private void Sides_Click(object sender, EventArgs e)
    {
        listBox_menu.Items.Clear();
        listBox_menu.Items.Add("Ex1");
        listBox_menu.Items.Add("Ex2");
    }
    private void AddtoOrder_Click(object sender, EventArgs e)
    {
        if(listBox_menu.SelectedItems.Count>0)
        {
            for (int i = 0; i < listBox_menu.SelectedItems.Count; i++)
            {
                listBox_order.Items.Add(listBox_menu.SelectedItems[i].ToString());
                lblTotalCost.Text = (CalculateTotalCost(listBox_menu.SelectedItems[i].ToString(),true)).ToString();
            }
        }
    }
    private void RemoveFromOrder_Click(object sender, EventArgs e)
    {
        if (listBox_order.SelectedItems.Count > 0)
        {
            listBox_order.Items.Remove(listBox_order.SelectedItem);
        }
        Order = null;
        for (int i = 0; i < listBox_order.Items.Count; i++)
        {
            Order += listBox_order.Items[i].ToString() + " , ";
        }
        Cost = 0;
        if (listBox_order.Items.Count > 0)
        {
            for (int i = 0; i < listBox_order.Items.Count; i++)
            {
                Cost = (CalculateTotalCost(listBox_order.Items[i], true));
            }
        }
        lblTotalCost.Text = Cost.ToString();
    }
    private void Submit_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Customer name: " + txtBoxCustomerName.Text + " Orders: " + Order + " Total cost: " + Cost);
    }

First define two global variables, then use the CalculateTotalCost function (which I defined).

My answer has been updated.

Output (tested in Visual Studio 2017, .Net Framework 4.5.2):

Output

These are my codes:

    public Form1()
    {
        InitializeComponent();
        listBox_menu.SelectionMode = SelectionMode.MultiExtended;
    }
    double Cost = 0;
    string Order = null;
    public double CalculateTotalCost(object input, bool Total)
    {
        if (Total == true)
        {
            switch (input)
            {
                case "Salad":
                    Cost += 2500;
                    break;
                case "Rice":
                    Cost += 3000;
                    break;
                case "non-alcoholic beer":
                    Cost += 1000;
                    break;
                case "Water":
                    Cost += 200;
                    break;
                case "Ex1":
                    Cost += 2200;
                    break;
                default:
                    Cost += 2200;
                    break;
            }
        }
        else
        {
            switch (input)
            {
                case "Salad":
                    Cost -= 2500;
                    break;
                case "Rice":
                    Cost -= 3000;
                    break;
                case "non-alcoholic beer":
                    Cost -= 1000;
                    break;
                case "Water":
                    Cost -= 200;
                    break;
                case "Ex1":
                    Cost -= 2200;
                    break;
                default:
                    Cost -= 2200;
                    break;
            }
        }
        return Cost;
    }
    private void Entrees_Click(object sender, EventArgs e)
    {
        listBox_menu.Items.Clear();
        listBox_menu.Items.Add("Salad");
        listBox_menu.Items.Add("Rice");
    }
    private void Drinks_Click(object sender, EventArgs e)
    {
        listBox_menu.Items.Clear();
        listBox_menu.Items.Add("non-alcoholic beer");
        listBox_menu.Items.Add("Water");
    }
    private void Sides_Click(object sender, EventArgs e)
    {
        listBox_menu.Items.Clear();
        listBox_menu.Items.Add("Ex1");
        listBox_menu.Items.Add("Ex2");
    }
    private void AddtoOrder_Click(object sender, EventArgs e)
    {
        if(listBox_menu.SelectedItems.Count>0)
        {
            for (int i = 0; i < listBox_menu.SelectedItems.Count; i++)
            {
                listBox_order.Items.Add(listBox_menu.SelectedItems[i].ToString());
                lblTotalCost.Text = (CalculateTotalCost(listBox_menu.SelectedItems[i].ToString(),true)).ToString();
            }
        }
    }
    private void RemoveFromOrder_Click(object sender, EventArgs e)
    {
        if (listBox_order.SelectedItems.Count > 0)
        {
            listBox_order.Items.Remove(listBox_order.SelectedItem);
        }
        Order = null;
        for (int i = 0; i < listBox_order.Items.Count; i++)
        {
            Order += listBox_order.Items[i].ToString() + " , ";
        }
        Cost = 0;
        if (listBox_order.Items.Count > 0)
        {
            for (int i = 0; i < listBox_order.Items.Count; i++)
            {
                Cost = (CalculateTotalCost(listBox_order.Items[i], true));
            }
        }
        lblTotalCost.Text = Cost.ToString();
    }
    private void Submit_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Customer name: " + txtBoxCustomerName.Text + " Orders: " + Order + " Total cost: " + Cost);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文