![](/img/trans.png)
[英]C# How can I assign a context menu to a tray icon when the tray icon is not on the same form?
[英]Single click to open menu for tray icon in C#
如何在單擊而不是右鍵單擊時強制顯示托盤圖標的上下文菜單。
我嘗試過使用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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.