C#ListBox中的Item拖拽代码分享

我们先来看下运行效果图

创新互联专业提供成都服务器托管服务,为用户提供五星数据中心、电信、双线接入解决方案,用户可自行在线购买成都服务器托管服务,并享受7*24小时金牌售后服务。

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

大家可以测试运行下,有其他问题可以在下方的留言区讨论,感谢大家对创新互联的支持。


文章名称:C#ListBox中的Item拖拽代码分享
当前URL:http://ybzwz.com/article/ispsgi.html