在Form.Designer.cs文件中对于listBox处理:
listBox.MouseDoubleClick += new system。Windows.Forms.MouseEventHandler(listBox1_MouseDoubleClick);
在Form.cs代码文件中增加函数:
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = listBox1.IndexFromPoint(e.Location);
if(index != ListBox.NoMatches)
{
MessageBox.Show("这里是双击事件处理代码");
}
else
{
listBox1.SelectIndex = -1;
MessageBox.Show("没有选中Item");
}
}
完成!