OutlookBarBandCollection.cs
Upload User: nnpulika
Upload Date: 2013-02-15
Package Size: 597k
Code Size: 2k
Category:

StatusBar

Development Platform:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Windows.Forms;
  4. using UtilityLibrary.WinControls;
  5. namespace UtilityLibrary.Collections
  6. {
  7. /// <summary>
  8. /// Summary description for OutlookBarBandCollection.
  9. /// </summary>
  10. public class OutlookBarBandCollection  : System.Collections.CollectionBase, IEnumerable
  11. {
  12. #region Events
  13.         public event EventHandler Changed;
  14. #endregion
  15. #region Class Variables
  16. // Back reference to the parent control
  17. OutlookBar parentBar = null;
  18. #endregion
  19. #region Constructors
  20. public OutlookBarBandCollection(OutlookBar bar)
  21. {
  22. parentBar = bar;
  23. }
  24. #endregion
  25. #region Methods
  26.         public int Add(OutlookBarBand band)
  27. {
  28. if (Contains(band)) return -1;
  29. int index = InnerList.Add(band);
  30. RaiseChanged();
  31. return index;
  32. }
  33. public bool Contains(OutlookBarBand band)
  34. {
  35. return InnerList.Contains(band);
  36. }
  37. public int IndexOf(OutlookBarBand band)
  38. {
  39. return InnerList.IndexOf(band);
  40. }
  41. public void Remove(OutlookBarBand band)
  42. {
  43. // Make sure currentBandIndex is always valid
  44. int currentBandIndex = parentBar.GetCurrentBand();
  45. bool updateCurrentIndex = currentBandIndex != -1 && currentBandIndex == Count - 1;
  46. InnerList.Remove(band);
  47. if ( updateCurrentIndex )
  48. {
  49.                 // Since we just removed the currently selected band,
  50.                 // set the new selected band to last band
  51. if ( Count > 0 )
  52. parentBar.SetCurrentBand(Count-1);
  53. }
  54. RaiseChanged();
  55. }
  56. public OutlookBarBand this[int index]
  57. {
  58. get { 
  59. if ( index < 0 || index >= Count) 
  60. return null;
  61. return (OutlookBarBand) InnerList[index]; 
  62. }
  63. }
  64. #endregion
  65. #region Implementation
  66.         void RaiseChanged()
  67. {
  68. if (Changed != null) Changed(this, null);
  69. }
  70. #endregion
  71. }
  72. }