【问题标题】:How can one get a ContextMenuStrip to show on left click of a NotifyIcon?如何在左键单击 NotifyIcon 时显示 ContextMenuStrip?
【发布时间】:2011-04-04 14:45:34
【问题描述】:

我有一个分配给 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;
    }
}

【问题讨论】:

    标签: c# .net winforms notifyicon contextmenustrip


    【解决方案1】:

    您应该可以使用以下代码:

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

    Here's a good thread 关于 MSDN 网站上的主题。

    【讨论】:

    • 非常感谢您的快速回复!效果很好。
    • 在这种情况下使用 System.Reflection 会导致性能损失吗?
    猜你喜欢
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 2014-01-31
    • 2013-01-18
    • 1970-01-01
    相关资源
    最近更新 更多