gpt4 book ai didi

c# - 单击通知图标时如何以编程方式显示上下文菜单?

转载 作者:行者123 更新时间:2023-11-30 15:10:11 24 4
gpt4 key购买 nike

我有一个示例 C# Windows 窗体 here .我需要在单击鼠标左键时显示通知图标的上下文菜单。我已经标记了在哪里编写所需的代码,如下所示:

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);
}

关于c# - 单击通知图标时如何以编程方式显示上下文菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3545640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com