簡體   English   中英

單擊打開C#中托盤圖標的菜單

[英]Single click to open menu for tray icon in C#

如何在單擊而不是右鍵單擊時強制顯示托盤圖標的上下文菜單。

我嘗試過使用MouseClick事件,但eventargs的鼠標位置為x0y0。

這應該為你做:

private void notifyIcon1_Click(object sender, EventArgs e)
        {
            contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y);
        }

我發現另一種方法可以更好地工作:

private void notifyIcon1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            System.Reflection.MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            mi.Invoke(notifyIcon1, null);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM