如何检测哪个鼠标按钮双击表格,即左,右或中?
更新 我使用的是.NET2.0
答案 0 :(得分:2)
查看MouseDoubleClick和MouseEventArgs以及MouseButtons Enumeration
MouseDoubleClick是Form事件之一。
答案 1 :(得分:2)
将最后点击的按钮存储在 MouseUp 事件中,然后在双击事件中检查该按钮。示例代码:
MouseButtons _lastButtonUp = MouseButtons.None;
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
_lastButtonUp = e.Button;
}
private void Form1_DoubleClick(object sender, EventArgs e)
{
switch (_lastButtonUp)
{
case System.Windows.Forms.MouseButtons.Left:
MessageBox.Show("left double click");
break;
case System.Windows.Forms.MouseButtons.Right:
MessageBox.Show("right double click");
break;
case System.Windows.Forms.MouseButtons.Middle:
MessageBox.Show("middle double click");
break;
}
}
答案 2 :(得分:1)
在Whatever_Click或DoubleClick事件中,您可以查看MouseEventArgs e,其中包含按下的键。
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
Console.WriteLine("Left Mouse Button was clicked!");
else if (e.Button == MouseButtons.Middle)
Console.WriteLine("Middle Mouse Button was clicked!");
}
其他按钮包括MouseButtons.Right,MouseButtons.Left
答案 3 :(得分:0)
在form_MouseDoubleClick
事件中,您可以追踪
void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Do Operation
}
}