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

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

有帮助吗?

解决方案

这应该适合你:

private void notifyIcon1_Click(object sender, EventArgs e)
        {
            contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y);
        }

其他提示

我发现另一种方法可以更好地运作:

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);
        }
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top