代码之家  ›  专栏  ›  技术社区  ›  Sam

单击打开C中托盘图标的菜单#

  •  8
  • Sam  · 技术社区  · 16 年前

    如何强制在单击托盘图标时显示该图标的上下文菜单,而不是右键单击该图标。

    我尝试使用mouselick事件,但eventargs的鼠标位置为x0y0。

    2 回复  |  直到 8 年前
        1
  •  12
  •   CodeLikeBeaker    16 年前

    这应该为您做到:

    private void notifyIcon1_Click(object sender, EventArgs e)
            {
                contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y);
            }
    
        2
  •  9
  •   gillonba    15 年前

    另一种我发现效果更好的方法是:

    private void notifyIcon1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                System.Reflection.MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                mi.Invoke(notifyIcon1, null);
            }
        }