Sam*_*Sam 8 c# contextmenu winforms
如何在单击而不是右键单击时强制显示托盘图标的上下文菜单.
我尝试过使用MouseClick事件,但eventargs的鼠标位置为x0y0.
Cod*_*ker 12
这应该为你做:
private void notifyIcon1_Click(object sender, EventArgs e)
{
contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y);
}
Run Code Online (Sandbox Code Playgroud)
我发现另一种方法可以更好地工作:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7311 次 |
| 最近记录: |