LblLabel.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. 
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace Dongke.WinForm.Controls
  6. {
  7. /// <summary>
  8. /// 标准标签控件
  9. /// </summary>
  10. [ToolboxBitmap(typeof(Label))]
  11. public class LblLabel : Label, IDKControl, IMustInput
  12. {
  13. #region 成员变量
  14. /// <summary>
  15. /// 控件是否是必须输入项目
  16. /// </summary>
  17. private bool _mustInput = false;
  18. private bool _showMustInputAlert = true;
  19. #endregion
  20. #region 构造函数
  21. /// <summary>
  22. /// 标准标签控件
  23. /// </summary>
  24. public LblLabel()
  25. {
  26. this.BackColor = Color.Transparent;
  27. this.AutoSize = true;
  28. }
  29. #endregion
  30. #region 属性
  31. /// <summary>
  32. /// 获取或设置控件是否是必须输入项目
  33. /// </summary>
  34. [DefaultValue(false)]
  35. [Description("获取或设置控件是否是必须输入项目。"), Category("CustomerEx")]
  36. public bool MustInput
  37. {
  38. get
  39. {
  40. return this._mustInput;
  41. }
  42. set
  43. {
  44. if (this._mustInput != value)
  45. {
  46. this._mustInput = value;
  47. this.Invalidate();
  48. }
  49. }
  50. }
  51. #endregion
  52. #region 重写属性
  53. /// <summary>
  54. /// 获取或设置控件的前景色
  55. /// </summary>
  56. public override Color ForeColor
  57. {
  58. get
  59. {
  60. if (this._mustInput)
  61. {
  62. return Constant.LABEL_FORECOLOR_MUSTINPUT;
  63. }
  64. return base.ForeColor;
  65. }
  66. //set
  67. //{
  68. // //if (!this._mustInput)
  69. // //{
  70. // // base.ForeColor = value;
  71. // //}
  72. //}
  73. }
  74. /// <summary>
  75. /// 获取或设置一个值,该值指示是否自动调整控件的大小以完整显示其内容
  76. /// </summary>
  77. [DefaultValue(true)]
  78. public override bool AutoSize
  79. {
  80. get
  81. {
  82. return base.AutoSize;
  83. }
  84. set
  85. {
  86. base.AutoSize = value;
  87. }
  88. }
  89. /// <summary>
  90. /// 获取或设置控件的背景色
  91. /// </summary>
  92. [DefaultValue(typeof(Color), "Transparent")]
  93. public override Color BackColor
  94. {
  95. get
  96. {
  97. return base.BackColor;
  98. }
  99. set
  100. {
  101. base.BackColor = value;
  102. }
  103. }
  104. /// <summary>
  105. /// 获取或设置控件是否显示必须输入项目提示
  106. /// </summary>
  107. [Description("获取或设置控件是否显示必须输入项目提示。"), Category("CustomerEx")]
  108. [DefaultValue(true)]
  109. [Bindable(false)]
  110. [Browsable(false)]
  111. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  112. [EditorBrowsable(EditorBrowsableState.Never)]
  113. public bool ShowMustInputAlert
  114. {
  115. get
  116. {
  117. return this._showMustInputAlert;
  118. }
  119. set
  120. {
  121. if (this._showMustInputAlert != value)
  122. {
  123. this._showMustInputAlert = value;
  124. }
  125. }
  126. }
  127. /// <summary>
  128. /// 清除输入项
  129. /// </summary>
  130. public virtual void ClearValue()
  131. {
  132. this.Text = string.Empty;
  133. }
  134. #endregion
  135. }
  136. }