代码 :图是布局
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;
using System.Collections;
namespace WindowsFormsApplicationListBoxAdd_Remove
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)//添加按钮(左边的添加到右边)
{
ArrayList listRemove = new ArrayList();//存诸转移的项
foreach (object obj in lstPeople.SelectedItems)
{
lstAdd.Items.Add(obj);
listRemove.Add(obj);
}
foreach (object obj in listRemove)//删除已转移的项
{
lstPeople.Items.Remove(obj);
}
}
private void btnRemove_Click(object sender, EventArgs e)//从右边的移回左边
{
ArrayList listRemove = new ArrayList();
foreach (object obj in lstAdd.SelectedItems)
{
lstPeople.Items.Add(obj);
listRemove.Add(obj);
}
foreach (object obj in listRemove)
{
lstAdd.Items.Remove(obj);
}
}
private void button1_Click(object sender, EventArgs e)//全部转移
{
foreach (object obj in lstPeople.Items)
{
lstAdd.Items.Add(obj);
}
lstPeople.Items.Clear();
}
private void button2_Click(object sender, EventArgs e)//全部回收
{
foreach (object obj in lstAdd.Items)
{
lstPeople.Items.Add(obj);
}
lstAdd.Items.Clear();
}
}
}