简体   繁体   English

C#捕获鼠标右键单击ToolStrip下拉项目中单击

[英]C# Capture mouse right click in ToolStrip Drop Down Item Clicked

I want to capture the right click mouse event within the ToolStripDropDownItemClicked Event 我想在ToolStripDropDownItemClicked事件中捕获鼠标右键事件

private void toolStripDropDownButton1_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)

Based on the right click, i display a contextmenu. 基于右键单击,我显示一个上下文菜单。 So, I need to get both the item clicked and mouse click right. 因此,我需要同时单击该项目和单击鼠标右键。

You could use the MouseUp or MouseDown event it knows which button was pressed. 您可以使用MouseUp或MouseDown事件,它知道按下了哪个按钮。 The sender object is the menu item that was clicked. 发送者对象是被单击的菜单项。 Cast it to the correct type to access it's properties. 将其强制转换为正确的类型以访问其属性。 If you're not sure about the type you could use as and then check if the resulting object is null. 如果不确定类型可以用作哪种类型,然后检查结果对象是否为null。

void firstToolStripMenuItem_MouseUp(object sender, MouseEventArgs e)
{
    var toolStripMenuItem = (ToolStripMenuItem)sender;
    var nullIfOtherType = sender as ToolStripMenuItem;
    var right = e.Button == System.Windows.Forms.MouseButtons.Right;
}

How to get a right click mouse event? 如何获得右键单击鼠标事件? Changing EventArgs to MouseEventArgs causes an error in Form1Designer? 将EventArgs更改为MouseEventArgs会导致Form1Designer中出现错误?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM