2010-08-27 55 views
3

我有一個ContextMenuStrip分配給NotifyIcon,這與右鍵點擊罰款。如何獲得一個ContextMenuStrip顯示左鍵單擊NotifyIcon?

如何連接鼠標單擊事件來告訴NotifyIcon顯示其ContextMenuStrip?

private void taskbarIcon_MouseClick(object sender, MouseEventArgs e) 
{ 
    switch (e.Button) 
    { 
     case MouseButtons.Left: 
      // What could I use here? 
      break; 
     default: 
      break; 
    } 
} 

回答

9

您應該能夠使用下面的代碼:

if (e.Button == MouseButtons.Left) 
{ 
    MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", 
      BindingFlags.Instance |BindingFlags.NonPublic); 
    mi.Invoke(taskbarIcon, null); 
} 

Here's a good thread約在MSDN網站上的主題。

+0

謝謝你的快速反應堆!它工作完美。 – hydrogen 2010-08-27 21:35:19

+0

I <3 System.Reflection – hydrogen 2010-08-27 21:49:31

+0

在這種情況下使用System.Reflection是否會導致性能損失? – AnAurelian 2011-01-13 18:16:51

相關問題