Invoke NotifyIcon's Context Menu

后端 未结 4 700
陌清茗
陌清茗 2020-11-29 04:32

I want to have it such that left clicking on the NotifyIcon also causes the context menu (set with the ContextMenuStrip property) to open as well. How would I achieve this?

4条回答
  •  爱一瞬间的悲伤
    2020-11-29 04:59

    use the following code to show context menu on both right and left click on notifyicon, if you find any issue then text me at arshad_mcs786@hotmail.com (arshad from Islamabd)
    //System.Runtime.InteropServices use thi as reference

        [DllImport("User32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
        public static extern bool SetForegroundWindow(HandleRef hWnd);
    
        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            SetForegroundWindow(new HandleRef(this, this.Handle));
            int x = Control.MousePosition.X;
            int y = Control.MousePosition.Y;
             x = x - 10;
            y = y - 40;
            this.contextMenuStrip1.Show(x,y );
            //this.PointToClient(Cursor.Position)
        }
    

提交回复
热议问题