日期:2014-05-17 浏览次数:20947 次
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; namespace C4PlusWForm { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void listBox1_MouseDown(object sender, MouseEventArgs e) { // 双击后触发动作 if (e.Clicks > 1) { listBox2.Items.Add(listBox1.SelectedItem); listBox1.Items.Remove(listBox1.SelectedItem); System.Console.WriteLine("listBox1_MouseDown...DoubleClick"); } // 单击动作 else { int index = listBox1.IndexFromPoint(e.X, e.Y); string str = listBox1.Items[index].ToString(); DragDropEffects ddeLb1 = DoDragDrop(str, DragDropEffects.All); if (ddeLb1 == DragDropEffects.All) { listBox1.Items.RemoveAt(listBox1.IndexFromPoint(e.X, e.Y)); } } System.Console.WriteLine("listBox1_MouseDown" + e.Clicks); } private void listBox2_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat)) { string str = (string)e.Data.GetData( DataFormats.StringFormat); listBox2.Items.Add(str); } } private void listBox2_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void listBox1_DoubleClick(object sender, EventArgs e) { System.Console.WriteLine("listBox1_DoubleClick"); } } }