样式如下:

实现的代码一:

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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//实现">"功能,将左边一项移到右边
private void button1_Click(object sender, EventArgs e)
{
//listBox1.Items.RemoveAt(listBox1.SelectedIndex);
//listBox2.Items.Add(listBox1.SelectedIndex.ToString());
//获取listbox1的所有选中的项
if (this.listBox1.SelectedItems.Count > 0)
{
string list1Remove = this.listBox1.SelectedItem.ToString();
//判断是否添加到listbox2
if (!this.listBox2.Items.Contains(list1Remove))
{
//添加人员到listbox2中
this.listBox2.Items.Add(list1Remove);
//移除listbox1中
this.listBox1.Items.Remove(list1Remove);
}
}
}

//实现"<"功能,将右边一项移到左边
private void button3_Click(object sender, EventArgs e)
{
if (this.listBox2.SelectedItems.Count > 0)
{
string list2Remove = this.listBox2.SelectedItem.ToString();
//判断是否添加到listbox2
if (!this.listBox1.Items.Contains(list2Remove))
{
//添加人员到listbox2中
this.listBox1.Items.Add(list2Remove);
//移除listbox1中
this.listBox2.Items.Remove(list2Remove);
}
}
}

//实现">>"功能,将左边所有项移到右边
private void button2_Click(object sender, EventArgs e)
{
listBox2.Items.AddRange(listBox1.Items);
listBox1.Items.Clear();
}

//实现"<<"功能,将右边所有项移到左边
private void button4_Click(object sender, EventArgs e)
{
listBox1.Items.AddRange(listBox2.Items);
listBox2.Items.Clear();
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

//将文本添加到左边listBox中
private void button5_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
listBox1.Items.Add(textBox1.Text.ToString());
}

}
//删除左边listBox某一项
private void button6_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (textBox1.Text == listBox1.Items[i].ToString())
{
listBox1.Items.RemoveAt(i);
i--;
}
}
}
}
//删除左边listBox所有项
private void button7_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
}

}


实现的代码二:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LisBox控件的操作
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.AddRange(listBox2.Items);
listBox2.Items.Clear();

}

private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{

}

//实现>功能
private void button1_Click(object sender, EventArgs e)
{
//获取listbox1里面的值
if (this.listBox1.SelectedItems.Count > 0)
{
string checkPeople = this.listBox1.SelectedItem.ToString();
if (!this.listBox2.Items.Contains(checkPeople))
{
//添加人员到listbox2中
this.listBox2.Items.Add(checkPeople);
//移除listbox1中
this.listBox1.Items.Remove(checkPeople);
}
}
else {
MessageBox.Show("该人员已经转移过");
}

}

//实现<功能
private void button7_Click(object sender, EventArgs e)
{
//获取listbox2里面的值
if (this.listBox2.SelectedItems.Count > 0)
{
string checkPeople = this.listBox2.SelectedItem.ToString();
if (!this.listBox1.Items.Contains(checkPeople))
{
//添加人员到listbox1中
this.listBox1.Items.Add(checkPeople);
//移除listbox2中
this.listBox2.Items.Remove(checkPeople);
}
}
else
{
MessageBox.Show("该人员已经转移过");
}
}

private void Form1_Load(object sender, EventArgs e)
{

}

//实现>>功能
private void button2_Click(object sender, EventArgs e)
{
listBox2.Items.AddRange(listBox1.Items);
listBox1.Items.Clear();
}

//删除左边的所有项
private void button6_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}

//将文本加到左面的listBox
private void button4_Click(object sender, EventArgs e)
{
if (textBox1.Text != "") {
listBox1.Items.Add(textBox1.Text);
textBox1.Clear(); //清除textbox的里面的值
}
}

//删除左面选择的一项
private void button5_Click(object sender, EventArgs e)
{
if (this.listBox1.SelectedItems.Count > 0)
{
this.listBox1.Items.RemoveAt(this.listBox1.SelectedItems.Count);
}
else {
MessageBox.Show("您还没有选择,请选择一项进行操作");
}
}

private void toolStripButton1_Click(object sender, EventArgs e)
{

}

private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{

}
}
}

C#学习笔记:ListBox控件的用法的更多相关文章

  1. Python:GUI之tkinter学习笔记1控件的介绍及使用

    相关内容: tkinter的使用 1.模块的导入 2.使用 3.控件介绍 Tk Button Label Frame Toplevel Menu Menubutton Canvas Entry Mes ...

  2. iOS学习笔记——基础控件(上)

    本篇简单罗列一下一些常用的UI控件以及它们特有的属性,事件等等.由于是笔记,相比起来不会太详细 UIView 所有UI控件都继承于这个UIView,它所拥有的属性必是所有控件都拥有,这些属性都是控件最 ...

  3. Android笔记---常用控件以及用法

    这篇文章主要记录下Android的常用控件以及使用的方法,Android 给我们提供了大量的UI控件,合理地使用这些控件就可以非常轻松地编写出相当不错的界面,这些是Android学习的基础,没有什么业 ...

  4. ios 学习笔记之控件属性

    1.文本框 设置密码属性:Secure Text Entry 勾选; 设置文本框带清除属性: Clear Button =Is always visible;  默认是不带清除属性:Never app ...

  5. jQuery学习笔记(控件位置定位、尺寸大小的获取等)

    想做一个幽灵按钮出来,效果大概如下图: 当点击按钮的时候,会有四根线条从四个方向飞入,经历从“无-有-无”的闪入过程. 那么我的设计想法是,先在HTML中定义一个按钮,然后在jQuery中设计按钮点击 ...

  6. 学习笔记-menusript控件中条目权限设置使用

    在做一个小程序的时候,偶然发现了使用menusript控件做权限设置的方法,仅此标记,以供参考. 首先创建一个实例:testuseright.sln, 在项目文件里创建两个窗体:Form1.cs和us ...

  7. IOS 学习笔记(7) 控件 分隔栏控件(UISegmentControl)的使用方法

    分隔栏控件的系统默认式样一共有3种,分别是“普通式样”,"边框式样","条状式样" 分隔栏控件中有一个momentary属性,默认时NO.当开发者配置成YES时 ...

  8. IOS 学习笔记(6) 控件 文本域(UITextField)的使用方法

    UITextField控件的诸多特性都和UITextView相似,比如成为输入文本焦点时键盘自动显示,支持长按弹出动作选项,能够接收输入事件(开始输入,修改内容,结束输入和点击回车等). 1.特有的特 ...

  9. IOS 学习笔记(5) 控件 文本视图(UITextView)的使用方法

    相对于UILabell所支持的较短文本内容,UITextView对于长文本的支持更好.UITextView能够以滚动的方式全部浏览到长文本,并且就像UILabel那样,从ISO6,他也提供了对NSAt ...

随机推荐

  1. style文件的指定

    新建资源文件   写资源文件 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/prese ...

  2. WPF数据验证方式

    WPF有两种数据验证的方式: 1 在数据对象上进行验证:普通属性验证或者实现IDataErrorInfo接口 2 可以再绑定规则上进行验证:ExceptionValidationRule异常验证规则 ...

  3. sql xml 查询指定节点值,以及节点属性值

    SELECT   top 10  [HFMBDATA].query('(/Items/Item[@ID=''tbBryj''])').value('(//TextValue)[1]','nvarcha ...

  4. wpf 事件参数 绑定到viewmdoel

    public sealed class EventCommand : TriggerAction<DependencyObject> { public static readonly De ...

  5. LINQ查询表达式---------orderby子句

    LINQ查询表达式---------orderby子句 LINQ可以按元素的一个或多个属性对元素进行排序. class Program { public class PerInfo { public ...

  6. Xdite:永葆热情的上瘾式学习法(套路王:每天总结自己,反省自己的作息规律,找到自己的幸运时间、幸运方法,倒霉时间、倒霉方法。幸运是与注意力挂钩的。重复才能让自己登峰造极,主动去掉运气部分来训练自己。游戏吸引自己的几个原因非常适合训练自己)good

    版权声明 本文首发自微信公共帐号: 学习学习再学习(xiaolai-xuexi) 无需授权即可转载, 甚至无需保留以上版权声明: 转载时请务必注明作者. 以下是<共同成长社区>第 58 次 ...

  7. oracle利用透明网关访问mssql

    遇到一个客户,有个需求,想将mssql中的数据抽取到oracle中.经过上网查找,感觉gateway这个工具可以实现,因此就搭建实验环境进行测试.首先在oracle delivery上面下载对应的安装 ...

  8. DEPLOYING NATIVE UWP (UNIVERSAL WINDOWS PLATFORM) APPS FOR JAVA DEVELOPERS & PUBLISHING THEM TO THE MICROSOFT STORE

    原文: DEPLOYING NATIVE UWP (UNIVERSAL WINDOWS PLATFORM) APPS FOR JAVA DEVELOPERS & PUBLISHING THEM ...

  9. UWP中String 转为Path Data

    定义方法: Geometry PathMarkupToGeometry(string pathMarkup) { string xaml = "<Path " + " ...

  10. 在Delphi中创建线程,请一定使用BeginThread()代替CreateThread()创建线程!(更好的管理异常)

    在Delphi中创建线程,请一定使用BeginThread()代替CreateThread()创建线程! 如果直接使用Win32的API函数CreateThread()创建多个线程,也是可以创建的.但 ...