public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
listBox1.SelectionMode = SelectionMode.MultiSimple;
listBox2.SelectionMode = SelectionMode.MultiSimple;
listBox1.Items.Add(1); ;
listBox1.Items.Add(2);
listBox1.Items.Add(3);
listBox1.Items.Add(4);
listBox1.Items.Add(5);
button1.Click +=
new
EventHandler(button_Click);
button2.Click +=
new
EventHandler(button_Click);
button3.Click +=
new
EventHandler(button_Click);
button4.Click +=
new
EventHandler(button_Click);
}
void
button_Click(
object
sender, EventArgs e)
{
switch
((sender
as
Button).Text)
{
case
">"
: ItemMove(listBox1, listBox2);
break
;
case
"<"
: ItemMove(listBox2, listBox1);
break
;
case
">>"
: ItemMove(listBox1, listBox2,
true
);
break
;
case
"<<"
: ItemMove(listBox2, listBox1,
true
);
break
;
}
}
void
ItemMove(ListBox a, ListBox b,
bool
all=
false
)
{
var st =
new
ArrayList();
if
(all)
foreach
(var item
in
a.Items) st.Add(item);
else
foreach
(var item
in
a.SelectedItems) st.Add(item);
foreach
(var item
in
st)
{
b.Items.Add(item);
a.Items.Remove(item);
}
}
}
请发表评论