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

状态条

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using UtilityLibrary.Menus;
  5. namespace UtilityLibrary.Collections
  6. {
  7. public class MenuCommandCollection : CollectionWithEvents
  8. {
  9. #region Class Variables
  10. protected string extraText;
  11. protected Font extraFont;
  12. protected Color extraTextColor;
  13. protected Brush extraTextBrush;
  14. protected Color extraBackColor;
  15. protected Brush extraBackBrush;
  16. #endregion
  17. #region Constructors
  18. public MenuCommandCollection()
  19. {
  20. // Define defaults for internal state
  21. extraText = "";
  22. extraFont = SystemInformation.MenuFont;
  23. extraTextColor = SystemColors.ActiveCaptionText;
  24. extraTextBrush = null;
  25. extraBackColor = SystemColors.ActiveCaption;
  26. extraBackBrush = null;
  27. }
  28. #endregion
  29. #region Properties
  30. public bool VisibleItems()
  31. {
  32. foreach(MenuCommand mc in base.List)
  33. {
  34. // Is the item visible?
  35. if (mc.Visible)
  36. {
  37. // And its not a separator...
  38. if (mc.Text != "-")
  39. {
  40. // Then should return 'true' except when we are a sub menu item ourself
  41. // in which case there might not be any visible children which means that
  42. // this item would not be visible either.
  43. if ((mc.MenuCommands.Count > 0) && (!mc.MenuCommands.VisibleItems()))
  44. continue;
  45. return true;
  46. }
  47. }
  48. }
  49. return false;
  50. }
  51. public string ExtraText
  52. {
  53. get { return extraText; }
  54. set { extraText = value; }
  55. }
  56. public Font ExtraFont
  57. {
  58. get { return extraFont; }
  59. set { extraFont = value; }
  60. }
  61. public Color ExtraTextColor
  62. {
  63. get { return extraTextColor; }
  64. set { extraTextColor = value; }
  65. }
  66. public Brush ExtraTextBrush
  67. {
  68. get { return extraTextBrush; }
  69. set { extraTextBrush = value; }
  70. }
  71. public Color ExtraBackColor
  72. {
  73. get { return extraBackColor; }
  74. set { extraBackColor = value; }
  75. }
  76. public Brush ExtraBackBrush
  77. {
  78. get { return extraBackBrush; }
  79. set { extraBackBrush = value; }
  80. }
  81. public MenuCommand this[int index]
  82. {
  83. // Use base class to process actual collection operation
  84. get { return (base.List[index] as MenuCommand); }
  85. }
  86. public MenuCommand this[string text]
  87. {
  88. get 
  89. {
  90. // Search for a MenuCommand with a matching title
  91. foreach(MenuCommand mc in base.List)
  92. if (mc.Text == text)
  93. return mc;
  94. return null;
  95. }
  96. }
  97. #endregion
  98. #region Methods
  99. public MenuCommand Add(MenuCommand _value)
  100. {
  101. // Use base class to process actual collection operation
  102. base.List.Add(_value as object);
  103. return _value;
  104. }
  105. public void AddRange(MenuCommand[] values)
  106. {
  107. // Use existing method to add each array entry
  108. foreach(MenuCommand page in values)
  109. Add(page);
  110. }
  111. public void Remove(MenuCommand value)
  112. {
  113. // Use base class to process actual collection operation
  114. base.List.Remove(value as object);
  115. }
  116. public void Insert(int index, MenuCommand value)
  117. {
  118. // Use base class to process actual collection operation
  119. base.List.Insert(index, value as object);
  120. }
  121. public bool Contains(MenuCommand value)
  122. {
  123. // Use base class to process actual collection operation
  124. return base.List.Contains(value as object);
  125. }
  126. public int IndexOf(MenuCommand value)
  127. {
  128. // Find the 0 based index of the requested entry
  129. return base.List.IndexOf(value);
  130. }
  131. #endregion
  132. }
  133. }