如何获得一个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.
更多推荐
发布评论