如何让 ContextMenuStrip 在单击 NotifyIcon 时显示?

发布于 2024-09-16 20:09:11 字数 371 浏览 3 评论 0原文

我有一个分配给 NotifyIcon 的 ContextMenuStrip,并且右键单击即可正常工作。

如何连接鼠标单击事件来告诉 NotifyIcon 显示其 ContextMenuStrip?

private void taskbarIcon_MouseClick(object sender, MouseEventArgs e)
{
    switch (e.Button)
    {
        case MouseButtons.Left:
            // What could I use here?
            break;
        default:
            break;
    }
}

I have a ContextMenuStrip assigned to a NotifyIcon and this works with the right click fine.

How may I wire up the mouse-click event to tell the NotifyIcon to show its ContextMenuStrip?

private void taskbarIcon_MouseClick(object sender, MouseEventArgs e)
{
    switch (e.Button)
    {
        case MouseButtons.Left:
            // What could I use here?
            break;
        default:
            break;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-09-23 20:09:11

您应该能够使用以下代码:

if (e.Button == MouseButtons.Left)
{
   MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", 
            BindingFlags.Instance |BindingFlags.NonPublic);
    mi.Invoke(taskbarIcon, null);
}

MSDN 网站上有一个关于该主题的好帖子

You should be able to use the following code:

if (e.Button == MouseButtons.Left)
{
   MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", 
            BindingFlags.Instance |BindingFlags.NonPublic);
    mi.Invoke(taskbarIcon, null);
}

Here's a good thread about the subject at MSDN site.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文