国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

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

2019-10-29 21:03:28
字體:
來源:轉載
供稿:網友

我們先來看下運行效果圖

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();    }  }}

大家可以測試運行下,有其他問題可以在下方的留言區討論,感謝大家對VEVB武林網的支持。


注:相關教程知識閱讀請移步到c#教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彰武县| 桦川县| 山西省| 襄汾县| 黄平县| 景东| 嘉义县| 红原县| 雷山县| 鹤岗市| 固镇县| 沧州市| 千阳县| 石柱| 镇康县| 祥云县| 罗江县| 淄博市| 井冈山市| 普陀区| 鄂尔多斯市| 佛山市| 晋江市| 伊宁市| 资溪县| 喀什市| 安达市| 鄢陵县| 库尔勒市| 蕉岭县| 秦皇岛市| 葫芦岛市| 宜城市| 青河县| 阳高县| 邻水| 庆安县| 江永县| 宝山区| 项城市| 西盟|