/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.Text = "listBox控件使用示例";//给窗体的text赋值
label1.Text = "我国的主要大城市有:";
label1.AutoSize = true;
label2.Text = "我曾经去过的主要大城市有:";
label2.AutoSize = true;
string[] strCity = {"北京","上海","天津","重庆","哈尔滨","长春","沈阳","昆明",
"合肥","福州","兰州","广州","南宁","贵阳","海口","石家庄","郑州","武汉","长沙",
"南京","南昌","呼和浩特","银川","西宁","济南","太原","成都","香港","澳门","台北"};//表示的是一维的数组,数组最多可以达到60维,交错数组加方括弧在外边
for(int i = 0; i < strCity.Length; i++)//所有的数组标记都是从0开始,变量使用前要申明//把地址放在列表里
{
listBox1.Items.Add(strCity[i]);
}
this.listBox1.SelectionMode = SelectionMode.MultiExtended;//代表的是form1,因为他在类里 //属性加等号负值 //允许多项选择
this.listBox2.Text = "";
this.listBox2.SelectionMode = SelectionMode.MultiExtended;
is.button1.Text = ">";//定义按钮上面显示〉号 图案
this.button2.Text = ">>";
this.button3.Text = "<";
his.button4.Text = "<<";
//添加事件,回到布局窗口建立事件回到button1,双击到代码窗口
private void button1_Click(object sender, System.EventArgs e)
{
}
往里边导入数据
编程时先构建 结构
private void button1_Click(object sender, System.EventArgs e)
{
for(int i = 0; i <= listBox1.SelectedItems.CountCount - 1;i++)//进行定义//被选择的那些所有的//用小于时直接写减号,如果带等于就减1
{
listBox2.Items.Add(listBox1.SelectedItems[i]);//方法家括弧,加分号//数组加[]//索引i必须是Int//
}
从listBox2种剪切listBox1
for(int i = listBox1.SelectedItems.Count - 1;i>=0;i--)//从最后一个被选中的往前删到0为止)
{
listBox1.Items.Remove(listBox1.SelectedItems[i]);//移出
}
运行的时候按住ctrl选中几个城市,可以导入到右侧的列表中
阅读(1118) | 评论(0) | 转发(0) |