我该如何强制在点击托盘图标时显示上下文菜单,而不仅仅是右键单击。
我尝试使用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);
}
}