如何在单击而不是右键单击时强制显示托盘图标的上下文菜单。
我尝试使用 MouseClick 事件,但 eventargs 的鼠标位置位于 x0y0。
如何在单击而不是右键单击时强制显示托盘图标的上下文菜单。
我尝试使用 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);
}
}