c#点餐系统源码

c#餐厅点餐系统源码:

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 Form1_Load(object sender, EventArgs e)
        {
            int left = Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2;
            int top = Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2;
            this.Location = new Point(left, top);
            //1.在加载的时候统计菜的数量,每样菜都有对应的序号按钮
            //循环遍历
            foreach (Control control  in flowLayoutPanel1.Controls)
            {
                Button btn = new Button();
                //Controls是每样菜的整个panel容器
                btn.Tag = control;
                foreach (Control item in control.Controls)
                {

                    if (item.Tag.ToString()=="index")
                    {
                        btn.Text = item.Text;
                    }
                    
                }
                btn.Size = new Size(50, 30);
                btn.Font = new Font("", 15);
                flowLayoutPanel14.Controls.Add(btn);
                //添加按钮事件
                btn.Click += Btn_Click;
            }
            
        }
        int count = 0;
        private void Btn_Click(object sender, EventArgs e)
        { 
        //sender参数:事件的发起者,这是哪个对象触发的事件,那么这个sender就是谁
            Button clickbtn = (Button)sender;
            Control menu = (Control)clickbtn.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.Font = new Font("",15);
            flowLayoutPanel15.Controls.Add(label);
            label39.Text = count + "¥";
        }
    }
}

运行结果

c#点餐系统源码_第1张图片

你可能感兴趣的:(C#练习)