C# 如何在单击通知图标时以编程方式显示上下文菜单?
我有一个C#windows表单示例。我需要在鼠标左键单击时显示通知图标的上下文菜单。我已将所需代码的书写位置标记如下:C# 如何在单击通知图标时以编程方式显示上下文菜单?,c#,winforms,contextmenu,notifyicon,C#,Winforms,Contextmenu,Notifyicon,我有一个C#windows表单示例。我需要在鼠标左键单击时显示通知图标的上下文菜单。我已将所需代码的书写位置标记如下: private void button1_Click(object sender, EventArgs e) { //Need to show the context menu here } 请帮忙 左键单击图标时显示菜单 private void NotifyIcon_MouseClick(object sender, MouseEventArgs e) {
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);
}