1、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Ex067public partial class Form1 : Formpublic Form1()InitializeComponent();private void btn_add_Click(object sender
2、, EventArgs e)if (txt_add.Text = “) /文本框为空MessageBox.Show(“添加的内容不能为空!“);txt_add.Focus(); /获取焦点elseif (listBox1.Items.Count 0) /判断列表框中是否有项/循环比较是否有重复项,有则放弃添加for (int i = 0; i listBox1.Items.Count; i+)if (string.Compare(listBox1.Itemsi.ToString(), txt_add.Text) = 0)MessageBox.Show(“列表框中已有相同项,不能添加!“); /提示信息txt_add.Text = “; /清空文本框txt_add.Focus();return;listBox1.Items.Add(txt_add.Text.ToString(); /添加项txt_add.Text = “;elselistBox1.Items.Add(txt_add.Text.ToString(); /将文本框中的数据添加到列表框txt_add.Text = “;