C#基本使用checkedListBox




using System;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        string[] items = { "雞排", "水煎包","百葉豆腐","煎餃","蛋餅","飯糰","三明治","漢堡","豆漿","牛肉炒飯",
        "蝦仁炒飯","肉絲炒飯","路肉飯","控肉飯","燙青菜","三杯雞","牛小排"};
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (string tmp in items)
            {
                checkedListBox1.Items.Add(tmp);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                checkedListBox1.SetItemChecked(i, false);
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            Form2 form = new Form2();
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                if (checkedListBox1.GetItemChecked(i))
                {
                    form.richTextBox1.Text += checkedListBox1.Items[i].ToString() + ",";
                }
            }

            form.Show();

            if (form.richTextBox1.Text == "")
            {
                MessageBox.Show("阿你是不餓喔");
            }
        }
    }
}
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Jarvis 的頭像
    Jarvis

    Jarvis Blog

    Jarvis 發表在 痞客邦 留言(0) 人氣()