繁体   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