如何获得一个ContextMenuStrip显示左键单击NotifyIcon?(How can one get a ContextMenuStrip to show on left click of

编程入门 行业动态 更新时间:2024-10-26 06:25:52
如何获得一个ContextMenuStrip显示左键单击NotifyIcon?(How can one get a ContextMenuStrip to show on left click of a NotifyIcon?)

我有一个ContextMenuStrip分配给NotifyIcon,这与右键点击罚款。

如何连接鼠标单击事件来告诉NotifyIcon显示其ContextMenuStrip?

private void taskbarIcon_MouseClick(object sender, MouseEventArgs e) { switch (e.Button) { case MouseButtons.Left: // What could I use here? break; default: break; } }

I have a ContextMenuStrip assigned to a NotifyIcon and this works with the right click fine.

How may I wire up the mouse-click event to tell the NotifyIcon to show its ContextMenuStrip?

private void taskbarIcon_MouseClick(object sender, MouseEventArgs e) { switch (e.Button) { case MouseButtons.Left: // What could I use here? break; default: break; } }

最满意答案

你应该能够使用下面的代码:

if (e.Button == MouseButtons.Left) { MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance |BindingFlags.NonPublic); mi.Invoke(taskbarIcon, null); }

这里有一个有关MSDN站点主题的好主意 。

You should be able to use the following code:

if (e.Button == MouseButtons.Left) { MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance |BindingFlags.NonPublic); mi.Invoke(taskbarIcon, null); }

Here's a good thread about the subject at MSDN site.

更多推荐

本文发布于:2023-07-26 17:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1278917.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:左键   单击   如何获得   ContextMenuStrip   click

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!