引言: 
  今天做前台C#的同事,纠结在了,“拖拽事件使用的listBox1_MouseDown(s, e)会‘屏蔽掉’双击事件的使用的listBox1_DoubleClick”,这一问题上。查证多方资料,没好的解决方法。 
  于是笔者休息时实验了一下,使用e.Clicks这个属性可以解决。具体请参阅正文。 

正文: 
  实现机理:((MouseEventArgs)e).Clicks通过值的{1, 2, ...}可以区分单击双击。于是可将双击事件实现写入e.Clicks > 1的语句,来达到预期效果。 
  细节不叨叨,直接上代码。 
C#代码   收藏代码
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9.   
  10. namespace C4PlusWForm  
  11. {  
  12.     public partial class Form2 : Form  
  13.     {  
  14.         public Form2()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.   
  19.         private void listBox1_MouseDown(object sender, MouseEventArgs e)  
  20.         {  
  21.             // 双击后触发动作  
  22.             if (e.Clicks > 1)  
  23.             {  
  24.                 listBox2.Items.Add(listBox1.SelectedItem);  
  25.                 listBox1.Items.Remove(listBox1.SelectedItem);  
  26.                 System.Console.WriteLine("listBox1_MouseDown...DoubleClick");  
  27.   
  28.             }  
  29.                 // 单击动作  
  30.             else {  
  31.                 int index = listBox1.IndexFromPoint(e.X, e.Y);  
  32.                 string str = listBox1.Items[index].ToString();  
  33.                 DragDropEffects ddeLb1 = DoDragDrop(str, DragDropEffects.All);  
  34.   
  35.                 if (ddeLb1 == DragDropEffects.All)  
  36.                 {  
  37.                     listBox1.Items.RemoveAt(listBox1.IndexFromPoint(e.X, e.Y));  
  38.                 }  
  39.             }  
  40.             System.Console.WriteLine("listBox1_MouseDown" + e.Clicks);  
  41.         }  
  42.   
  43.         private void listBox2_DragDrop(object sender, DragEventArgs e)  
  44.         {  
  45.             if (e.Data.GetDataPresent(DataFormats.StringFormat))  
  46.             {  
  47.                 string str = (string)e.Data.GetData(  
  48.                     DataFormats.StringFormat);  
  49.   
  50.                 listBox2.Items.Add(str);  
  51.             }  
  52.         }  
  53.   
  54.         private void listBox2_DragOver(object sender, DragEventArgs e)  
  55.         {  
  56.             e.Effect = DragDropEffects.All;  
  57.         }  
  58.   
  59.         private void listBox1_DoubleClick(object sender, EventArgs e)  
  60.         {  
  61.             System.Console.WriteLine("listBox1_DoubleClick");  
  62.         }  
  63.   
  64.     }  
  65. }  

  实验效果图如下: 
 
引用地址:http://www.iteye.com/topic/1123345