C# NotifyIcon实现单击左键也弹出菜单的方法

private void systemNotifyIcon_MouseClick(object sender, MouseEventArgs e)
      {

          switch (e.Button)
          {
              case MouseButtons.Left:

                   systemNotifyIcon.ContextMenuStrip = systemNotifyLeftMenuStrip;
                   Type t = typeof(NotifyIcon);
                   System.Reflection.MethodInfo mi = t.GetMethod("ShowContextMenu", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                   mi.Invoke(this.systemNotifyIcon, null);
                   systemNotifyIcon.ContextMenuStrip = systemNotifyRightMenuStrip;

                   break;
              case MouseButtons.Right:
                  systemNotifyIcon.ContextMenuStrip = systemNotifyRightMenuStrip;
                  break;
              case MouseButtons.Middle:
                 if (this.WindowState == FormWindowState.Minimized)
                  {
                      this.WindowState = FormWindowState.Normal;

                  }

                  break;

              case MouseButtons.None:
              default:
                  break;
          }//end switch

      }//end method

posted @ 2015-08-30 14:57  撷一程  阅读(1263)  评论(0编辑  收藏  举报