你如何获得不同的上下文菜单,如果你LT-点击或RT-点击一个图标通知? [英] How do you get a different Context Menu if you Lt-Click or Rt-Click on a notify icon?

查看:137
本文介绍了你如何获得不同的上下文菜单,如果你LT-点击或RT-点击一个图标通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于从系统托盘的应用程序。我有一个很好的上下文菜单,如果你右键点击它,但是我想不同的上下文菜单中显示出来,如果你留一下就可以了。现在我做了不同的菜单显示了

I have a application that is based out of the system tray. I have a nice context menu if you right click on it however I would like a different context menu to show up if you left click on it. Right now I make the different menu show up with

private void niTrayIcon_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
        cmsTrayLeftClick.Show(Cursor.Position);
    }

}

这使得菜单出现,但点击关闭菜单不让它消失,使菜单消失,唯一的办法要么是点击一个项目或RT单击托盘图标。

That makes the menu show up but clicking off the menu does not make it go away, the only way to make the menu disappear is either click on a item or rt click on the tray icon.

我有也想出了这个技巧,但它确实觉得它是做了正确的道路。

I have also came up with this hack but it does feel like it is the correct way to do it.

private void niTrayIcon_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
        niTrayIcon.ContextMenuStrip = cmsTrayLeftClick;
        MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
        mi.Invoke(niTrayIcon, null);
        niTrayIcon.ContextMenuStrip = cmsTrayRtClick;
    }
}

这是做正确的方式还是有一个更优雅的方式?

Is this the correct way of doing it or is there a more elegant way?

推荐答案

由于没有其他人发布的作品我想这样做是正确的方式方法

As no one else has posted a way that works I guess the correct way of doing it is

private void niTrayIcon_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
        niTrayIcon.ContextMenuStrip = cmsTrayLeftClick;
        MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
        mi.Invoke(niTrayIcon, null);
        niTrayIcon.ContextMenuStrip = cmsTrayRtClick;
    }
}

这篇关于你如何获得不同的上下文菜单,如果你LT-点击或RT-点击一个图标通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆