求Listbox的操作!!
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EX2_123
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button7_Click(object sender, EventArgs e)
{
Close();
}
private void button1_Click(object sender, EventArgs e)
{
int i;
for (i = listBox1.Items.Count - 1; i >= 0; i--)
{
listBox2.Items.Add(listBox1.Items[i]);
listBox1.Items.RemoveAt(i);
}
ShowBtnEn();
}
private void button3_Click(object sender, EventArgs e)
{
int i;
for (i = listBox2.Items.Count - 1; i >= 0; i--)
if (listBox2.GetSelected(i))
{
listBox1.Items.Add(listBox2.Items[i]);
listBox2.Items.RemoveAt(i);
}
ShowBtnEn();
}
private void button2_Click(object sender, EventArgs e)
{
int i;
for (i = listBox1.Items.Count - 1; i >= 0; i--)
if (listBox1.GetSelected(i))
{
listBox2.Items.Add(listBox1.Items[i]);
listBox1.Items.RemoveAt(i);
}
ShowBtnEn();
}
private void button6_Click(object sender, EventArgs e)
{
}
void ShowBtnEn()
{
if (listBox1.Items.Count != 0)
{
if (listBox2.Items.Count == 0)
{
button3.Enabled = false;
button4.Enabled = false;
button1.Enabled = true;
button2.Enabled = true;
}
else
{
button3.Enabled = true;
button4.Enabled = true;
button1.Enabled = true;
button2.Enabled = true;
}
}
else
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
button4.Enabled = true;
}
}
private void button4_Click(object sender, EventArgs e)
{
int i;
for (i = listBox2.Items.Count - 1; i >= 0; i--)
{
listBox1.Items.Add(listBox2.Items[i]);
listBox2.Items.RemoveAt(i);
}
ShowBtnEn();
}
private void listBox1_DragLeave(object sender, EventArgs e)
{
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{ int i;
string s1;
for (i = listBox1.Items.Count; i > 0; i--)
{
}
}
}
}
这个是我编的程序。
剩下的作业要求
1.是通过↑↓按钮调整items的位置
2.拖曳直接在两个listbox间移动items
做好的大神请回帖 谢谢!~