ChevronMenu.cs
上传用户:nnpulika
上传日期:2013-02-15
资源大小:597k
文件大小:3k
源码类别:

状态条

开发平台:

C#

  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using UtilityLibrary.Collections;
  5. using UtilityLibrary.Menus;
  6. using UtilityLibrary.WinControls;
  7. namespace UtilityLibrary.CommandBars
  8. {
  9. /// <summary>
  10. /// Summary description for ToolBarItemMenu.
  11. /// </summary>
  12. public class ChevronMenu : PopupMenu
  13. {
  14. #region Class Variables
  15. ToolBarItemCollection items = new ToolBarItemCollection();
  16. #endregion
  17. #region Properties
  18. public ToolBarItemCollection Items
  19. {
  20. set { items = value; Attach(); }
  21. get { return items; }
  22. }
  23. #endregion
  24. #region Implementation
  25. void AddSubMenu(MenuCommand parentMenuCommand, MenuItemExCollection items)
  26. {
  27. for ( int i = 0; i < items.Count; i++ )
  28. {
  29.                 // I know these menu items are actually MenuItemExs
  30. MenuItemEx item = (MenuItemEx)items[i];
  31. MenuCommand currentMenuCommand = new MenuCommand(item.Text, item.Icon,
  32. (Shortcut)item.Shortcut, item.ClickHandler, item);
  33. parentMenuCommand.MenuCommands.Add(currentMenuCommand);
  34. if ( item.MenuItems.Count > 0 )
  35. AddSubMenu(currentMenuCommand, item.MenuItems);
  36. }
  37. }
  38. void AddSubMenu(MenuCommand parentMenuCommand, Menu.MenuItemCollection items)
  39. {
  40. for ( int i = 0; i < items.Count; i++ )
  41. {
  42. // I know these menu items are actually MenuItemExs
  43. MenuItemEx item = (MenuItemEx)items[i];
  44. MenuCommand currentMenuCommand = new MenuCommand(item.Text, (Bitmap)item.Icon,
  45. (Shortcut)item.Shortcut, item.ClickHandler, item);
  46. parentMenuCommand.MenuCommands.Add(currentMenuCommand);
  47. if ( item.MenuItems.Count > 0 )
  48. AddSubMenu(currentMenuCommand, item.MenuItems);
  49. }
  50. }
  51. void Attach()
  52. {
  53. // Cleanup previous menus
  54. MenuCommands.Clear();
  55. foreach (ToolBarItem item in items)
  56. {
  57. string text = item.Text;
  58. if ( text == string.Empty || text == null )
  59. text = item.ToolTip;
  60. if ( item.Style == ToolBarItemStyle.Separator )
  61. text = "-";
  62. // If this is a combobox
  63. if ( item.ComboBox != null )
  64. {
  65. MenuCommands.Add(new MenuCommand(item.ComboBox));
  66. item.ComboBox.Visible = true;
  67. // I know where this combobox comes from
  68. ComboBoxBase cbb = (ComboBoxBase)item.ComboBox;
  69. cbb.ToolBarUse = false;
  70. continue;
  71. }
  72. MenuCommand currentMenuCommand = new MenuCommand(text, (Bitmap)item.Image, 
  73. (Shortcut)item.Shortcut, item.ClickHandler, item);
  74. MenuCommands.Add(currentMenuCommand);
  75. // If we have a menubar
  76. if ( item.MenuItems != null)
  77. AddSubMenu(currentMenuCommand, item.MenuItems);
  78. }
  79. }
  80. #endregion
  81. }
  82. }