码迷,mamicode.com
首页 > 其他好文 > 详细

[SharpDevelop]菜单状态更新

时间:2014-07-19 20:06:17      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   art   

方式一

在Idle方法中更新

bubuko.com,布布扣
 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);
bubuko.com,布布扣
 1 void UpdateMenu(object sender, EventArgs e)
 2         {
 3             UpdateMenus();
 4             UpdateToolbars();
 5         }
 6         
 7         void UpdateMenus()
 8         {
 9             // update menu
10             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;
bubuko.com,布布扣
 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

[SharpDevelop]菜单状态更新,布布扣,bubuko.com

[SharpDevelop]菜单状态更新

标签:style   blog   http   color   os   art   

原文地址:http://www.cnblogs.com/yhlx125/p/3849757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!