C# 怎样点击一个按钮时将label的Text内容显示到listBox1的Items中?

2024-11-26 07:17:52
推荐回答(1个)
回答1:

        private void button1_Click(object sender, EventArgs e)
        {
            string s = this.label1.Text;
            if (this.listBox1.Items.Contains(s))
                MessageBox.Show("不能重复添加!");
            else
                this.listBox1.Items.Add(s);
        }