winform中如何给button按钮定义一个单击鼠标中键事件
如题,我想给button按钮添加一个单击鼠标中键的事件,该怎么做?还有,我应当如何判断鼠标是否单击了中键?...
如题,我想给button按钮添加一个单击鼠标中键的事件,该怎么做?还有,我应当如何判断鼠标是否单击了中键?
展开
1个回答
2013-10-28
展开全部
button派生自control的,而control有一个mousedown事件,可以判断是哪一个键被按下,下面是一段摘抄自MSDN的代码,你可以参考一下 private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Update the mouse path with the mouse information
Point mouseDownLocation = new Point(e.X, e.Y);
string eventString = null;
switch (e.Button) {
case MouseButtons.Left:
eventString = "L";
break;
case MouseButtons.Right:
eventString = "R";
break;
case MouseButtons.Middle:
eventString = "M";
break;
case MouseButtons.XButton1:
eventString = "X1";
break;
case MouseButtons.XButton2:
eventString = "X2";
break;
case MouseButtons.None:
default:
break;
}
{
// Update the mouse path with the mouse information
Point mouseDownLocation = new Point(e.X, e.Y);
string eventString = null;
switch (e.Button) {
case MouseButtons.Left:
eventString = "L";
break;
case MouseButtons.Right:
eventString = "R";
break;
case MouseButtons.Middle:
eventString = "M";
break;
case MouseButtons.XButton1:
eventString = "X1";
break;
case MouseButtons.XButton2:
eventString = "X2";
break;
case MouseButtons.None:
default:
break;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询