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

状态条

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Drawing;
  4. namespace UtilityLibrary.Collections 
  5. {
  6. /// <summary>
  7. /// Summary description for RectangleCollection.
  8. /// </summary>
  9. public class RectangleCollection : IEnumerable
  10. {
  11. #region Events
  12. public event EventHandler Changed;
  13. #endregion
  14. #region Class Variables
  15. ArrayList items = new ArrayList();
  16. #endregion
  17. #region Constructors
  18. public RectangleCollection()
  19. {
  20. }
  21. #endregion
  22. #region Properties
  23. public int Count
  24. {
  25. get { return items.Count; }
  26. }
  27. #endregion
  28. #region Methods
  29. public IEnumerator GetEnumerator()
  30. {
  31. return items.GetEnumerator();
  32. }
  33. public int Add(Rectangle item)
  34. {
  35. if (Contains(item)) return -1;
  36. int index = items.Add(item);
  37. RaiseChanged();
  38. return index;
  39. }
  40. public void Clear()
  41. {
  42. while (Count > 0) RemoveAt(0);
  43. }
  44. public bool Contains(Rectangle item)
  45. {
  46. return items.Contains(item);
  47. }
  48. public int IndexOf(Rectangle item)
  49. {
  50. return items.IndexOf(item);
  51. }
  52. public void Remove(Rectangle item)
  53. {
  54. items.Remove(item);
  55. RaiseChanged();
  56. }
  57. public void RemoveAt(int index)
  58. {
  59. items.RemoveAt(index);
  60. RaiseChanged();
  61. }
  62. public void Insert(int index, Rectangle item)
  63. {
  64. items.Insert(index, item);
  65. RaiseChanged();
  66. }
  67. public Rectangle this[int index]
  68. {
  69. get { return (Rectangle) items[index]; }
  70. set {  items[index] = value; }
  71. }
  72. #endregion
  73. #region Implementation
  74. void RaiseChanged()
  75. {
  76. if (Changed != null) Changed(this, null);
  77. }
  78. #endregion
  79. }
  80. }