我有一个示例C#窗体here。我需要在鼠标左键单击时显示通知图标的上下文菜单。我已经在下面标记了所需代码的编写位置:
private void button1_Click(object sender, EventArgs e)
{
//Need to show the context menu here
}
请帮忙!
答案 0 :(得分:5)
在左键单击图标时显示菜单
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);
}