I have a sample C# windows form here . I need to show the notification icon's context menu when it is left-mouse clicked. I have marked where to write the needed codes as below:
private void button1_Click(object sender, EventArgs e)
{
//Need to show the context menu here
}
Please help!
To show the menu when your icon is left-clicked
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);
}
}
To show the menu when the button in your question is clicked
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.