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

状态条

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Windows.Forms;
  4. using System.Diagnostics;
  5. using UtilityLibrary.CommandBars;
  6. namespace UtilityLibrary.Collections
  7. {
  8. /// <summary>
  9. /// Summary description for RebarBandCollection.
  10. /// </summary>
  11. public class RebarBandCollection : System.Collections.CollectionBase, IEnumerable
  12. {
  13. #region Events
  14. public event EventHandler Changed;
  15. #endregion
  16. #region Class Variables
  17. ReBar parentRebar = null;
  18. #endregion
  19. #region Constructors
  20. public RebarBandCollection(ReBar bar)
  21. {
  22. parentRebar = bar;
  23. }
  24. #endregion
  25. #region Methods
  26. public int Add(ToolBarEx toolBar)
  27. {
  28. // Remove place Holder ToolBar
  29. // -- This toolbar makes sure Rebar has
  30. // some minimum height while on designig time
  31. if ( parentRebar.PlaceHolderAdded )
  32. parentRebar.RemovePlaceHolder();
  33. if (Contains(toolBar)) return -1;
  34. int index = InnerList.Add(toolBar);
  35. // Set ToolBar parent rebar
  36. toolBar.parentRebar = parentRebar;
  37. RaiseChanged();
  38. return index;
  39. }
  40. public bool Contains(ToolBarEx toolBar)
  41. {
  42. return InnerList.Contains(toolBar);
  43. }
  44. public int IndexOf(ToolBarEx toolBar)
  45. {
  46. return InnerList.IndexOf(toolBar);
  47. }
  48. public void Remove(ToolBarEx toolBar)
  49. {
  50. // Remove band from the native rebar controls first
  51. parentRebar.RemoveBand(IndexOf(toolBar));
  52. // Remove it from the collection
  53. InnerList.Remove(toolBar);
  54. toolBar.parentRebar = null;
  55. // Inform listeners to update
  56. RaiseChanged();
  57. // If we don't have any bands left, add
  58. // flag that we need to add the "place holder toolbar
  59. // --it will be added later when the sizing "sticks"
  60. if ( InnerList.Count == 0 && parentRebar.PlaceHolderAdded == false )
  61. parentRebar.AddPlaceHolderToolBar = true;
  62. }
  63. public new void Clear()
  64. {
  65. // Before wiping out all bands from
  66. // the collection, make sure we also
  67. // delete the bands from the native rebar control
  68. for ( int i = 0; i < InnerList.Count; i++ )
  69. {
  70. ToolBarEx tbe = (ToolBarEx)InnerList[i];
  71. tbe.parentRebar.RemoveBand(i);
  72. tbe.parentRebar = null;
  73. }
  74. // Now from the collection
  75. InnerList.Clear();
  76. // Inform listeners to update
  77. RaiseChanged();
  78. // We don't have any bands left, add
  79. // the ToolBar place holder
  80. if ( parentRebar.PlaceHolderAdded == false )
  81. parentRebar.AddPlaceHolder();
  82. }
  83. public ToolBarEx this[int index]
  84. {
  85. get { return (ToolBarEx) InnerList[index]; }
  86. }
  87. #endregion
  88. #region Implementation
  89. void RaiseChanged()
  90. {
  91. if (Changed != null) Changed(this, null);
  92. }
  93. #endregion
  94. }
  95. }