UCLEDNums.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 09-02-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCLEDNums.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Drawing;
  20. using System.Data;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows.Forms;
  24. namespace HZH_Controls.Controls
  25. {
  26. /// <summary>
  27. /// Class UCLEDNums.
  28. /// Implements the <see cref="System.Windows.Forms.UserControl" />
  29. /// </summary>
  30. /// <seealso cref="System.Windows.Forms.UserControl" />
  31. public partial class UCLEDNums : UserControl
  32. {
  33. /// <summary>
  34. /// The m value
  35. /// </summary>
  36. private string m_value;
  37. /// <summary>
  38. /// Gets or sets the value.
  39. /// </summary>
  40. /// <value>The value.</value>
  41. [Description("值"), Category("自定义")]
  42. public string Value
  43. {
  44. get { return m_value; }
  45. set
  46. {
  47. m_value = value;
  48. ReloadValue();
  49. }
  50. }
  51. /// <summary>
  52. /// The m line width
  53. /// </summary>
  54. private int m_lineWidth = 8;
  55. /// <summary>
  56. /// Gets or sets the width of the line.
  57. /// </summary>
  58. /// <value>The width of the line.</value>
  59. [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  60. public int LineWidth
  61. {
  62. get { return m_lineWidth; }
  63. set
  64. {
  65. m_lineWidth = value;
  66. foreach (UCLEDNum c in this.Controls)
  67. {
  68. c.LineWidth = value;
  69. }
  70. }
  71. }
  72. /// <summary>
  73. /// 获取或设置控件的前景色。
  74. /// </summary>
  75. /// <value>The color of the fore.</value>
  76. /// <PermissionSet>
  77. /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  78. /// </PermissionSet>
  79. [Description("颜色"), Category("自定义")]
  80. public override System.Drawing.Color ForeColor
  81. {
  82. get
  83. {
  84. return base.ForeColor;
  85. }
  86. set
  87. {
  88. base.ForeColor = value;
  89. foreach (UCLEDNum c in this.Controls)
  90. {
  91. c.ForeColor = value;
  92. }
  93. }
  94. }
  95. /// <summary>
  96. /// 获取或设置一个值,该值指示是否将控件的元素对齐以支持使用从右向左的字体的区域设置。
  97. /// </summary>
  98. /// <value>The right to left.</value>
  99. /// <PermissionSet>
  100. /// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  101. /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  102. /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
  103. /// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  104. /// </PermissionSet>
  105. public override RightToLeft RightToLeft
  106. {
  107. get
  108. {
  109. return base.RightToLeft;
  110. }
  111. set
  112. {
  113. base.RightToLeft = value;
  114. ReloadValue();
  115. }
  116. }
  117. /// <summary>
  118. /// Reloads the value.
  119. /// </summary>
  120. private void ReloadValue()
  121. {
  122. try
  123. {
  124. ControlHelper.FreezeControl(this, true);
  125. this.Controls.Clear();
  126. foreach (var item in m_value)
  127. {
  128. UCLEDNum uc = new UCLEDNum();
  129. if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
  130. uc.Dock = DockStyle.Right;
  131. else
  132. uc.Dock = DockStyle.Left;
  133. uc.Value = item;
  134. uc.ForeColor = ForeColor;
  135. uc.LineWidth = m_lineWidth;
  136. this.Controls.Add(uc);
  137. if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
  138. uc.SendToBack();
  139. else
  140. uc.BringToFront();
  141. }
  142. }
  143. finally
  144. {
  145. ControlHelper.FreezeControl(this, false);
  146. }
  147. }
  148. /// <summary>
  149. /// Initializes a new instance of the <see cref="UCLEDNums" /> class.
  150. /// </summary>
  151. public UCLEDNums()
  152. {
  153. InitializeComponent();
  154. Value = "0.00";
  155. }
  156. }
  157. }