如何实现:在任务栏图标单击鼠标左键弹出菜单?
notifyIcon.ContextMenu=contextMenuStrip;这一句可以实现单击鼠标右键时弹出菜单,如何实现单击左键跟右键一样的效果?

解决方案 »

  1.   

    在mousedown事件中加入 if(e.Button == MouseButtons.Left)     ContextMenu.Show(notifyIcon, e.Location);
      

  2.   

     private void notifyIcon1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    Control control = new Control(null, Control.MousePosition.X, Control.MousePosition.Y, 1, 1);
                    control.Visible = true;
                    control.CreateControl();
                    Point pos = new Point(0, 0);//这里的两个数字要根据你的上下文菜单大小适当地调整
                    this.contextMenuStrip1.Show(control, pos);
                }
            }
      

  3.   

    在点击左键时模拟点击右键: private readonly int MOUSEEVENTF_RightDown = 0x0008;
            private readonly int MOUSEEVENTF_RightUp = 0x0010;
            [DllImport("user32")]
            public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);         private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    mouse_event(MOUSEEVENTF_RightDown, e.X, e.Y, 0, 0);
                    mouse_event(MOUSEEVENTF_RightUp, e.X, e.Y, 0, 0); 
                }
            }