Detect right click on toolstrip button

萝らか妹 提交于 2019-12-13 21:05:59

问题


I have a toolstrip with a context menu and a toolstrip button in it with a click event. Initially I tried to assign the context menu to the button itself, but couldn't find a context menu in its property. So I assigned the context menu to the toolstrip. Now whenever I right click the button for the context menu to appear, the button click event is triggered. I want to check which mouse button is clicked, so I tired to cast event args to mouseeventargs:

if (((MouseEventArgs)e).Button != MouseButtons.Left) return;

but I got an exception that I can't do this cast. Can I either assign context menu to the button or detect which mouse button is clicked? Thanks


回答1:


You can try the MouseDown event of the ToolStripButton like this:

private void toolStripButton1_MouseDown(object sender, MouseEventArgs e){
   if(e.Button == MouseButtons.Right){
      //...
   }
}


来源:https://stackoverflow.com/questions/19544505/detect-right-click-on-toolstrip-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!