2011-04-07 63 views
2

我手動添加通知圖標到基於表單的應用程序的任務欄使用c#。該菜單已添加好,但是當我右鍵單擊該圖標時,該列表將顯示在任務欄下方作爲默認值。如何讓它出現在您通常所期望的位置?菜單項出現在任務欄上而不是上面

NotifyIcon notfiyIcon = new NotifyIcon(); 
      ContextMenu contextMenu = new ContextMenu(); 
      MenuItem menuItem = new MenuItem(); 

      menuItem.Text = "Exit"; 
      menuItem.Click += new System.EventHandler(this.btnLogOut_Click); 

      contextMenu.MenuItems.Add(menuItem); 
      contextMenu.MenuItems.Add("hello"); 
      notfiyIcon.ContextMenu = contextMenu; 

      notfiyIcon.Text = "Property Sales"; 

      Icon icon = new Icon("icon.ico"); 
      notfiyIcon.Icon = icon; 

      notfiyIcon.Visible = true; 

enter image description here

這是我想它會出現什麼。

enter image description here

+0

你是什麼意思_下面的任務欄_?你可以張貼截圖嗎?另外,什麼操作系統? – gideon 2011-04-07 17:53:40

+0

我添加了圖標 – JohnB 2011-04-07 17:58:56

回答

2

這是Windows上下文菜單的預期行爲。

通常,上下文菜單從鼠標位置向下打開,這是您在第一個屏幕截圖中看到的內容。在第二張屏幕截圖中,上下文菜單太高而無法向下打開(它會延伸到屏幕外),所以它會從鼠標位置向上打開以便完全可見。

您可以手動設置菜單位置,但出於一致性考慮,不建議使用。

相關問題