C#简易点餐系统

C#简易点餐系统_第1张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 餐馆
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            foreach (Control control in flowLayoutPanel1.Controls)
            {
                Button button = new Button();
                button.Tag = control;
                foreach (Control item in control.Controls)
                {
                    if (item.Tag.ToString()=="index")
                    {
                        button.Text = item.Text;

                    }
                }
                flowLayoutPanel14.Controls.Add(button);
                button.Click += Button_Click;
            }
        }
        int count = 0;
        private void Button_Click(object sender, EventArgs e)
        {
            Button click = (Button)sender;
            Control menu = (Control)click.Tag;
            Label label = new Label();
            foreach (Control item in menu.Controls)
            {
                if (item.Tag.ToString()=="name")
                {
                    label.Text = item.Text;
                }
                if (item.Tag.ToString()=="money")
                {
                    count += int.Parse(item.Text);
                    label.Tag = item.Text;
                }
                flowLayoutPanel15.Controls.Add(label);
                label39.Text = count + "¥";
            }
           
            label.Click += Label_Click;
        }

        private void Label_Click(object sender, EventArgs e)
        {
            Label cc = (Label)sender;
            cc.Dispose();
            count -= int.Parse(cc.Tag.ToString());
            label39.Text = count + "¥";
        }
    }
}

 

你可能感兴趣的:(C#简易点餐系统)