使用了menuStrip 菜单组件,">"为button1,"<"为button2,"下单"为button3 ,两个ListBox
画好菜单后
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < listBox1.SelectedItems.Count; i++) //选择菜品然后计数 { string menu = listBox1.SelectedItems[i].ToString(); listBox2.Items.Add(menu); } } private void button2_Click(object sender, EventArgs e) { for (int i = listBox2.SelectedItems.Count-1; i >=0 ; i--) //重最后一个开始删除 { listBox2.Items.Remove(listBox2.SelectedItems[i]); } }
private void SetListMenu(string[] data) //定义一个方法 { listBox1.Items.Clear(); for (int i = 0; i < data.Length; i++) { listBox1.Items.Add(data[i]); } }
插入菜品
private void 中餐ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "辣子鸡丁", "红烧排骨", "麻婆豆腐", "香脆里脊", "糖醋排骨", "宫保鸡丁", "香酥鸡", "醋熘白菜", "小鸡炖蘑菇", "猪肉炖粉条", "芹菜香干", "鱼香肉丝" }; SetListMenu(data); } private void 西餐ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "牛排", "猪扒", "意大利面", "鸡扒", "香辣鸡腿堡", "培根汉堡" }; SetListMenu(data); } private void 红酒ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "拉斐", "长城干红", "华夏干红", "张裕" }; SetListMenu(data); } private void 饮料ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "雪碧", "可乐", "奶茶", "红茶", "咖啡", "果汁", "开水" }; SetListMenu(data); } private void 汤ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "冬瓜排骨汤", "罗宋汤", "老鸭汤", "老母鸡汤", "紫菜蛋花汤", "三鲜汤" }; SetListMenu(data); } private void 冰激凌ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "草莓", "巧尔滋", "圣代", "哈根达斯" }; SetListMenu(data); } private void 点心ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "巧克力蛋糕", "草莓蛋糕", "苹果派", "水果" }; SetListMenu(data); } private void 小食ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "汉堡", "炸鸡腿", "薯条", "鸡块" }; SetListMenu(data); }
前面有几个组合菜品没有添加,因为我没有想到有什么菜!!!
最后面下单显示
private void button3_Click(object sender, EventArgs e) { string msg = string.Format("\t您共点餐{0}项\n\n点餐时间:{1}", listBox2.Items.Count,DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); MessageBox.Show(msg); }
时间: 2024-11-03 20:34:43