[SharpDevelop]菜單狀態更新

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   art   

方式一

在Idle方法中更新

 1 void OnApplicationIdle(object sender, EventArgs e) 2         { 3             // Use the Idle event to update the status of menu and toolbar. 4             // Depending on your application and the number of menu items with complex conditions, 5             // you might want to update the status less frequently. 6             UpdateMenuItemStatus(); 7         } 8          9         /// <summary>Update Enabled/Visible state of items in the main menu based on conditions</summary>10         void UpdateMenuItemStatus()11         {12             foreach (ToolStripItem item in menu.Items) {13                 if (item is IStatusUpdate)14                     (item as IStatusUpdate).UpdateStatus();15             }16         }
View Code

方式二

sealed class DefaultWorkbench : Form, IWorkbench

通過一個Timer來更新

1 toolbarUpdateTimer =  new System.Windows.Forms.Timer();2 toolbarUpdateTimer.Tick += new EventHandler(UpdateMenu);
 1 void UpdateMenu(object sender, EventArgs e) 2         { 3             UpdateMenus(); 4             UpdateToolbars(); 5         } 6          7         void UpdateMenus() 8         { 9             // update menu10             foreach (object o in TopMenu.Items) {11                 if (o is IStatusUpdate) {12                     ((IStatusUpdate)o).UpdateStatus();13                 }14             }15         }16         17         void UpdateToolbars()18         {19             if (ToolBars != null) {20                 foreach (ToolStrip toolStrip in ToolBars) {21                     ToolbarService.UpdateToolbar(toolStrip);22                 }23             }24         }
View Code

方式三

sealed partial class WpfWorkbench : FullScreenEnabledWindow, IWorkbench, System.Windows.Forms.IWin32Window

1   requerySuggestedEventHandler = new EventHandler(CommandManager_RequerySuggested);2   CommandManager.RequerySuggested += requerySuggestedEventHandler;
 1 EventHandler requerySuggestedEventHandler; 2  3 void CommandManager_RequerySuggested(object sender, EventArgs e) 4 { 5     UpdateMenu(); 6 } 7 void UpdateMenu() 8 { 9     MenuService.UpdateStatus(mainMenu.ItemsSource);10         foreach (ToolBar tb in toolBars) 11         {12     ToolBarService.UpdateStatus(tb.ItemsSource);13     }14 }
View Code

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.