C# ListBox中的Item拖拽代码分享
作者:彬菌 发布时间:2022-04-12 14:06:41
标签:C#,ListBox,Item
我们先来看下运行效果图
Form1.cs代码:
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;
using System.Collections;
namespace MoveItem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ArrayList list = new ArrayList();
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 10; i++)
{
list.Add(i);
string s = i.ToString();
listBox1.Items.Add(s);
}
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//单选,无法实现多选
//string str = this.listBox1.Text.Trim().ToString();
//if (listBox1.Items.Contains(str))
//{
// listBox1.Items.Remove(str);
// listBox2.Items.Add(str);
//}
for (int i=0;i<listBox1.SelectedIndices.Count;i++)
{
listBox2.Items.Add(listBox1.Items[listBox1.SelectedIndices[i]]);
listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]);
i--;
}
}
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox2.SelectedIndices.Count; i++)
{
listBox1.Items.Add(listBox2.Items[listBox2.SelectedIndices[i]]);
listBox2.Items.RemoveAt(listBox2.SelectedIndices[i]);
i--;
}
}
private void button3_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();
}
}
}
大家可以测试运行下,有其他问题可以在下方的留言区讨论,感谢大家对脚本之家的支持。
来源:https://www.idaobin.com/archives/967.html
0
投稿
猜你喜欢
- 一、什么是ASMASM是一个java字节码操纵框架,它能被用来动态生成类或者增强既有类的功能。ASM 可以直接产生二进制 class 文件,
- 首先,将json串转为一个JObject对象:JObject jo = (JObject)JsonConvert.DeserializeOb
- namespace ConsoleApplication1{ using System; &n
- 前段时间因为看JUC的源码,里面有大量关于unsafe的操作,所以就来看看了.写点笔记总结下(本文基于jdk1.8):unsafe可以帮我们
- 在java程序开发中,ftp用的比较多,经常打交道,比如说向FTP服务器上传文件、下载文件,本文给大家介绍如何利用jakarta commo
- 本文实例为大家分享了Android Webview使用小结,供大家参考,具体内容如下#采用重载URL的方式实现Java与Js交互在Andro
- 这是一篇入门级文章,高手请略过。在这篇文章中我们将学习如何用 Java 对图像进行剪裁并将剪裁出来的部分单独保存到文件中。我们将通过以下步骤
- 最近在学习AngularJS的知识,收获不少,不过因为自己平时工作时开发都是用的freemarker+springmvc来做的页面数据交互,
- @PropertySource加载自定义yml文件使用@PropertySource默认加载的是.xml或者 .properties文件,因
- 1 自定义类加载器自定义类加载器的代码很简单,只需要继承ClassLoader类,覆写findClass方法即可其默认实现是会抛出一个异常:
- DatagramSocket只允许数据报发送给指定的目标地址,而MulticastSocket可以将数据报以广播的方式发送至多个客户端。其主
- 代码一/// <summary> /// 截断字符串 /// </su
- 本文实例讲述了C#检测是否有u盘插入的方法。分享给大家供大家参考。具体如下:该C#代码可监控是否有u盘插入,同时可以监控其它驱动器的变化us
- 适配器(Adapter)模式:适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一
- 问题:1.线程 wait()方法使用有什么前提?2. 多线程之间如何进行通信?3. Java 中 notify 和 notifyAll 有什
- 应用场景:在Android开发过程中,有时需要调用手机自身设备的功能,本文侧重摄像头拍照功能的调用。知识点介绍:使用权限:调用手机自身设备功
- 本文实例为大家分享了Swing拆分窗格控件JSplitPane的使用方法,供大家参考,具体内容如下package day1115;impor
- public class OracleJdbcTest { &nbs
- 前言早就听说Go语言开发的服务不用任何架构优化,就可以轻松实现百万级别的qps。这得益于Go语言级别的协程的处理效率。协程不同于线程,线程是
- 前言:干了这几个项目,也做过几次文件上传下载,要么是copy项目以前的代码,要么是百度的,虽然做出来了,但学习一下原理弄透彻还是很有必要的。