[英]Show notification icon context menu after performing some action
我需要在執行某些操作后而不是單擊后立即在左右單擊中顯示通知圖標上下文菜單的上下文菜單。
它非常適合於左鍵單擊,如下所示:
sysTrayIcon.MouseClick += OnSysTrayClicked;
private static void OnSysTrayClicked(Object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
PerformActions();
MethodInfo oMethodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
oMethodInfo.Invoke(sysTrayIcon, null);
}
}
但是,右鍵單擊仍會自動處理,並且右鍵單擊時會顯示關聯的ContextMenuStrip
。 有什么方法可以用我的事件處理程序覆蓋它嗎?
有兩種選擇。
選項A:不要將上下文菜單分配給this.ContextMenuStrip。 您可以隨時手動打開上下文菜單。 請注意,strip.Top和strip.Left必須是屏幕的絕對坐標。
選項B:如果鼠標右鍵單擊,則取消分配this.ContextMenuStrip OnMouseDown,然后重新分配OnMouseUp。 請參閱此示例 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.