ListBox中有N个用户
双击Item是将选择的用户名添加到TextBox
效果如下 
         用户1;用户2;用户3;(Item的值为用户1  用户2 用户3
我现在想实现的就是当我们再双击用户1时textBox中删除用户1;
剩下用户2;用户3;

解决方案 »

  1.   

    双击时记下 Item的值 比如 :"用户1"
    判断 textBox.Text中是否有 "用户1;"
    如果没有 textBox.Text 中添加 "用户1;"
    如果有 textBox.Text 中 "用户1;" 用"" 取代
      

  2.   

    private void listBox1_DoubleClick(object sender, System.EventArgs e)
    {
    string str=listBox1.SelectedItem.ToString()+";";
    int i=this.textBox1.Text.IndexOf(str);
    if (this.textBox1.Text.IndexOf(str)==-1)
    {
    this.textBox1.Text=this.textBox1.Text+str;
    }
    else
    {
    this.textBox1.Text=this.textBox1.Text.Replace(str,"");
    }
    }