PropertyItem.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.ComponentModel;
  3. namespace FWindSoft.WinForm
  4. {
  5. public class PropertyItem
  6. {
  7. private object m_Value;
  8. public event EventHandler<ValueChangedArgs> OnValueChanged;
  9. public PropertyItem()
  10. {
  11. this.Name = string.Empty;
  12. this.DisplayName = String.Empty;
  13. this.Category = string.Empty;
  14. this.IsVisible = true;
  15. this.IsReadOnly = false;
  16. }
  17. public PropertyItem(string name, object value)
  18. : this()
  19. {
  20. this.Name = name;
  21. this.Value = value;
  22. this.DisplayName = name;
  23. }
  24. public PropertyCollection Owner { get; internal set; }
  25. #region 特殊处理属性值
  26. /// <summary>
  27. /// 属性值
  28. /// </summary>
  29. public object Value
  30. {
  31. get { return this.m_Value; }
  32. set
  33. {
  34. ValueChangedArgs args = new ValueChangedArgs(this.m_Value, value, this.Owner);
  35. bool changed = this.m_Value!=value;
  36. this.m_Value = value;
  37. if (changed && OnValueChanged != null)
  38. {
  39. OnValueChanged(this, args);
  40. }
  41. }
  42. }
  43. #endregion
  44. #region 属性维护
  45. /// <summary>
  46. /// 属性名称
  47. /// </summary>
  48. public string Name { get; set; }
  49. /// <summary>
  50. /// 是否可编辑
  51. /// </summary>
  52. public bool IsReadOnly { get; set; }
  53. /// <summary>
  54. /// 是否可见
  55. /// </summary>
  56. public bool IsVisible { get; set; }
  57. /// <summary>
  58. /// 分类
  59. /// </summary>
  60. public string Category { get; set; }
  61. /// <summary>
  62. /// 编辑器
  63. /// </summary>
  64. public virtual object Editor { get; set; }
  65. /// <summary>
  66. /// 属性名显示
  67. /// </summary>
  68. public string DisplayName { get; set; }
  69. /// <summary>
  70. /// 提示信息
  71. /// </summary>
  72. public string Description { get; set; }
  73. /// <summary>
  74. /// 类型转换
  75. /// </summary>
  76. public TypeConverter Convert { get; set; }
  77. #endregion
  78. }
  79. public class ValueChangedArgs : HandledEventArgs
  80. {
  81. public ValueChangedArgs(object oldValue,object newValue,PropertyCollection collection)
  82. {
  83. this.OldValue = oldValue;
  84. this.NewValue = newValue;
  85. this.ReferenceItems = collection;
  86. }
  87. /// <summary>
  88. /// 旧值
  89. /// </summary>
  90. public object OldValue { get; private set; }
  91. /// <summary>
  92. /// 新值
  93. /// </summary>
  94. public object NewValue { get; private set; }
  95. /// <summary>
  96. /// 关联项目集合
  97. /// </summary>
  98. public PropertyCollection ReferenceItems { get; private set; }
  99. }
  100. }