簡體   English   中英

單擊通知圖標時如何以編程方式顯示上下文菜單?

[英]How to show the context menu programmatically when click on notification icon?

在這里有一個示例C#窗體。 我需要在鼠標左鍵單擊時顯示通知圖標的上下文菜單。 我已經在下面標記了所需代碼的編寫位置:

private void button1_Click(object sender, EventArgs e)
{
        //Need to show the context menu here
}

請幫忙!

在左鍵單擊圖標時顯示菜單

private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        MethodInfo methodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu",
            BindingFlags.Instance | BindingFlags.NonPublic);

        methodInfo.Invoke(this.notifyIcon, null);
    }
}

單擊問題中的按鈕時顯示菜單

private void button1_Click(object sender, EventArgs e)
{
    //Need to show the context menu here
    MethodInfo methodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu",
        BindingFlags.Instance | BindingFlags.NonPublic);
    methodInfo.Invoke(this.notifyIcon, null);
}

暫無
暫無

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

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