C# winform 判断click事件点击的是左键还是右键

button.Click += new System.EventHandler(btn_Click);
private void btn_Click(object sender, EventArgs e)
{
//EventArgs继承自MouseEventArgs,所以可以强转
MouseEventArgs Mouse_e = (MouseEventArgs)e;


//点鼠标右键,return
if (Mouse_e.Button == MouseButtons.Right)
{
MessageBox.Show("右键!");
}

}


只有把EventArgs强制转换成MouseEventArgs就可以有相当于MouseDown事件的功能了 

button2.MouseDown += new MouseEventHandler(btn2_MouseDown);
private void btn2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
MessageBox.Show("右键");
}
}


转自:http://heisetoufa.iteye.com/blog/379634

你可能感兴趣的:(C# winform 判断click事件点击的是左键还是右键)