拉一個MenuStrip, SplitContainer和ListView元件
加入3個button
設定splitContainer1.Panel2的背景圖, 點選BackgroundImage選擇想要的背景圖片
更新ListView的套餐項目
1: private void package(Int16 num)
2: {
3: listView1.Clear(); //清空listView1中的原有內容
4: switch (num)
5: {
6: case 1:
7: listView1.Items.Add("烤魚", "烤魚", 5);
8: listView1.Items.Add("荔枝", "荔枝", 6);
9: listView1.Items.Add("水果", "水果", 7);
10: break;
11: case 2:
12: listView1.Items.Add("巧克力", "巧克力", 2);
13: listView1.Items.Add("薯條", "薯條", 4);
14: listView1.Items.Add("冰淇淋", "冰淇淋", 9);
15: break;
16: case 3:
17: listView1.Items.Add("紅酒", "紅酒", 0);
18: listView1.Items.Add("早餐", "早餐", 1);
19: listView1.Items.Add("水果", "水果", 8);
20: break;
21: }
22: }
更新套餐按鈕順序, 被點選的設定為Top,其餘Bottom
1: private void sortBtn(Int16 num)
2: {
3:
4: switch (num)
5: {
6: case 1:
7: button1.Dock = DockStyle.Top;
8: button2.Dock = DockStyle.Bottom;
9: button1.SendToBack();
10: button3.Dock = DockStyle.Bottom;
11: break;
12: case 2:
13: button2.Dock = DockStyle.Top;
14: button2.SendToBack();
15: button1.Dock = DockStyle.Bottom;
16: button3.Dock = DockStyle.Bottom;
17: break;
18: case 3:
19: button3.SendToBack();
20: button3.Dock = DockStyle.Top;
21: button3.SendToBack();
22: button2.Dock = DockStyle.Bottom;
23: button1.SendToBack();
24: button1.Dock = DockStyle.Bottom;
25: break;
26: }
27: }
在Form_Load事件加入listView1的大圖來源屬性(LargeImageList)設定
1:
2: private void Form1_Load(object sender, EventArgs e)
3: {
4:
5: listView1.LargeImageList = imageList1; //設定目前項以大圖標的形式顯示時用到的圖像
6:
7: }
imageList加入圖示
圖片來源: food icon
按下<確認>
button1~3的點選(Click)事件如下:
1: private void button3_Click(object sender, EventArgs e)
2: {
3: package(3);
4: sortBtn(3);
5: }
6: private void button2_Click(object sender, EventArgs e)
7: {
8: package(2);
9: sortBtn(2);
10: }
11:
12: private void button1_Click(object sender, EventArgs e)
13: {
14: package(1);
15: sortBtn(1);
16: }
最後加入判定套餐中哪些item被選中
1: private void listView1_SelectedIndexChanged(object sender, EventArgs e)
2: {
3: StringBuilder sb = new StringBuilder();
4: foreach( ListViewItem item in listView1.SelectedItems)
5: {
6: sb.Append(item.Text+",");
7: }
8: sb.Remove(sb.Length - 1, 1);
9: this.Text = sb.ToString();
10: }
成果展示:
全站熱搜
留言列表