入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。

GitHub:https://github.com/kwwwvagaa/NetWinformControl

码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

如果觉得写的还行,请点个 star 支持一下吧

欢迎前来交流探讨: 企鹅群568015492 企鹅群568015492

麻烦博客下方点个【推荐】,谢谢

  1. Install-Package HZH_Controls

https://www.cnblogs.com/bfyx/p/11364884.html

使用GID+画的,不了解的话请自行百度

添加一个类UCLEDNum ,继承UserControl

将数字拆分为单独的字,然后根据显示位置进行画出来,将显示位置定义为如下所示

  1. /* 显示位置序号
  2. * ****1***
  3. * * *
  4. * 6 2
  5. * * *
  6. * ****7***
  7. * * *
  8. * 5 3
  9. * * *
  10. * ****4***
  11. */

从上面可以看出,定义了1-7的位置,然后定义一个数字对应的显示列表

  1. 1 private static Dictionary<char, int[]> m_nums = new Dictionary<char, int[]>();
  2. 2 static UCLEDNum()
  3. 3 {
  4. 4 m_nums['0'] = new int[] { 1, 2, 3, 4, 5, 6 };
  5. 5 m_nums['1'] = new int[] { 2, 3 };
  6. 6 m_nums['2'] = new int[] { 1, 2, 5, 4, 7 };
  7. 7 m_nums['3'] = new int[] { 1, 2, 7, 3, 4 };
  8. 8 m_nums['4'] = new int[] { 2, 3, 6, 7 };
  9. 9 m_nums['5'] = new int[] { 1, 6, 7, 3, 4 };
  10. 10 m_nums['6'] = new int[] { 1, 6, 5, 4, 3, 7 };
  11. 11 m_nums['7'] = new int[] { 1, 2, 3 };
  12. 12 m_nums['8'] = new int[] { 1, 2, 3, 4, 5, 6, 7 };
  13. 13 m_nums['9'] = new int[] { 1, 2, 3, 4, 7, 6 };
  14. 14 m_nums['-'] = new int[] { 7 };
  15. 15 m_nums[':'] = new int[0];
  16. 16 m_nums['.'] = new int[0];
  17. 17 }

你看到了还有“-”,“:”,“.”这3个符号,是为了时间和数字时候使用

然后定义一个矩形区域来用作绘画区域,并且在SizeChanged事件中赋值

  1. Rectangle m_drawRect = Rectangle.Empty;
  2. void LEDNum_SizeChanged(object sender, EventArgs e)
  3. {
  4. m_drawRect = new Rectangle(1, 1, this.Width - 2, this.Height - 2);
  5. }

然后就是几个属性

  1. 1 private char m_value = '0';
  2. 2
  3. 3 [Description(""), Category("自定义")]
  4. 4 public char Value
  5. 5 {
  6. 6 get { return m_value; }
  7. 7 set
  8. 8 {
  9. 9 if (!m_nums.ContainsKey(value))
  10. 10 {
  11. 11 return;
  12. 12 }
  13. 13 if (m_value != value)
  14. 14 {
  15. 15 m_value = value;
  16. 16 Refresh();
  17. 17 }
  18. 18 }
  19. 19 }
  20. 20
  21. 21 private int m_lineWidth = 8;
  22. 22
  23. 23 [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  24. 24 public int LineWidth
  25. 25 {
  26. 26 get { return m_lineWidth; }
  27. 27 set
  28. 28 {
  29. 29 m_lineWidth = value;
  30. 30 Refresh();
  31. 31 }
  32. 32 }
  33. 33
  34. 34 [Description("颜色"), Category("自定义")]
  35. 35 public override System.Drawing.Color ForeColor
  36. 36 {
  37. 37 get
  38. 38 {
  39. 39 return base.ForeColor;
  40. 40 }
  41. 41 set
  42. 42 {
  43. 43 base.ForeColor = value;
  44. 44 }
  45. 45 }

最重要的重绘

  1. 1 protected override void OnPaint(PaintEventArgs e)
  2. 2 {
  3. 3 base.OnPaint(e);
  4. 4 e.Graphics.SetGDIHigh();
  5. 5 if (m_value == '.')
  6. 6 {
  7. 7 Rectangle r2 = new Rectangle(m_drawRect.Left + (m_drawRect.Width - m_lineWidth) / 2, m_drawRect.Bottom - m_lineWidth * 2, m_lineWidth, m_lineWidth);
  8. 8 e.Graphics.FillRectangle(new SolidBrush(ForeColor), r2);
  9. 9 }
  10. 10 else if (m_value == ':')
  11. 11 {
  12. 12 Rectangle r1 = new Rectangle(m_drawRect.Left + (m_drawRect.Width - m_lineWidth) / 2, m_drawRect.Top + (m_drawRect.Height / 2 - m_lineWidth) / 2, m_lineWidth, m_lineWidth);
  13. 13 e.Graphics.FillRectangle(new SolidBrush(ForeColor), r1);
  14. 14 Rectangle r2 = new Rectangle(m_drawRect.Left + (m_drawRect.Width - m_lineWidth) / 2, m_drawRect.Top + (m_drawRect.Height / 2 - m_lineWidth) / 2 + m_drawRect.Height / 2, m_lineWidth, m_lineWidth);
  15. 15 e.Graphics.FillRectangle(new SolidBrush(ForeColor), r2);
  16. 16 }
  17. 17 else
  18. 18 {
  19. 19 int[] vs = m_nums[m_value];
  20. 20 if (vs.Contains(1))
  21. 21 {
  22. 22 GraphicsPath path = new GraphicsPath();
  23. 23 path.AddLines(new Point[]
  24. 24 {
  25. 25 new Point(m_drawRect.Left + 2, m_drawRect.Top),
  26. 26 new Point(m_drawRect.Right - 2, m_drawRect.Top),
  27. 27 new Point(m_drawRect.Right - m_lineWidth-2, m_drawRect.Top+m_lineWidth),
  28. 28 new Point(m_drawRect.Left + m_lineWidth+2, m_drawRect.Top+m_lineWidth),
  29. 29 new Point(m_drawRect.Left + 2, m_drawRect.Top)
  30. 30 });
  31. 31 path.CloseAllFigures();
  32. 32 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  33. 33 }
  34. 34
  35. 35 if (vs.Contains(2))
  36. 36 {
  37. 37 GraphicsPath path = new GraphicsPath();
  38. 38 path.AddLines(new Point[]
  39. 39 {
  40. 40 new Point(m_drawRect.Right, m_drawRect.Top),
  41. 41 new Point(m_drawRect.Right, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2),
  42. 42 new Point(m_drawRect.Right-m_lineWidth/2, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2+m_lineWidth/2),
  43. 43 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2),
  44. 44 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Top+m_lineWidth),
  45. 45 new Point(m_drawRect.Right, m_drawRect.Top)
  46. 46 });
  47. 47 path.CloseAllFigures();
  48. 48 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  49. 49 }
  50. 50
  51. 51 if (vs.Contains(3))
  52. 52 {
  53. 53 GraphicsPath path = new GraphicsPath();
  54. 54 path.AddLines(new Point[]
  55. 55 {
  56. 56 new Point(m_drawRect.Right, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  57. 57 new Point(m_drawRect.Right, m_drawRect.Bottom),
  58. 58 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Bottom-m_lineWidth),
  59. 59 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  60. 60 new Point(m_drawRect.Right-m_lineWidth/2, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2-m_lineWidth/2),
  61. 61 new Point(m_drawRect.Right, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  62. 62 });
  63. 63 path.CloseAllFigures();
  64. 64 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  65. 65 }
  66. 66
  67. 67 if (vs.Contains(4))
  68. 68 {
  69. 69 GraphicsPath path = new GraphicsPath();
  70. 70 path.AddLines(new Point[]
  71. 71 {
  72. 72 new Point(m_drawRect.Left + 2, m_drawRect.Bottom),
  73. 73 new Point(m_drawRect.Right - 2, m_drawRect.Bottom),
  74. 74 new Point(m_drawRect.Right - m_lineWidth-2, m_drawRect.Bottom-m_lineWidth),
  75. 75 new Point(m_drawRect.Left + m_lineWidth+2, m_drawRect.Bottom-m_lineWidth),
  76. 76 new Point(m_drawRect.Left + 2, m_drawRect.Bottom)
  77. 77 });
  78. 78 path.CloseAllFigures();
  79. 79 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  80. 80 }
  81. 81
  82. 82 if (vs.Contains(5))
  83. 83 {
  84. 84 GraphicsPath path = new GraphicsPath();
  85. 85 path.AddLines(new Point[]
  86. 86 {
  87. 87 new Point(m_drawRect.Left, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  88. 88 new Point(m_drawRect.Left, m_drawRect.Bottom),
  89. 89 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Bottom-m_lineWidth),
  90. 90 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  91. 91 new Point(m_drawRect.Left+m_lineWidth/2, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2-m_lineWidth/2),
  92. 92 new Point(m_drawRect.Left, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  93. 93 });
  94. 94 path.CloseAllFigures();
  95. 95 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  96. 96 }
  97. 97
  98. 98
  99. 99 if (vs.Contains(6))
  100. 100 {
  101. 101 GraphicsPath path = new GraphicsPath();
  102. 102 path.AddLines(new Point[]
  103. 103 {
  104. 104 new Point(m_drawRect.Left, m_drawRect.Top),
  105. 105 new Point(m_drawRect.Left, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2),
  106. 106 new Point(m_drawRect.Left+m_lineWidth/2, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2+m_lineWidth/2),
  107. 107 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2),
  108. 108 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Top+m_lineWidth),
  109. 109 new Point(m_drawRect.Left, m_drawRect.Top)
  110. 110 });
  111. 111 path.CloseAllFigures();
  112. 112 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  113. 113 }
  114. 114
  115. 115 if (vs.Contains(7))
  116. 116 {
  117. 117 GraphicsPath path = new GraphicsPath();
  118. 118 path.AddLines(new Point[]
  119. 119 {
  120. 120 new Point(m_drawRect.Left+m_lineWidth/2, m_drawRect.Height/2+1),
  121. 121 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Height/2-m_lineWidth/2+1),
  122. 122 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Height/2-m_lineWidth/2+1),
  123. 123 new Point(m_drawRect.Right-m_lineWidth/2, m_drawRect.Height/2+1),
  124. 124 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Height/2+m_lineWidth/2+1),
  125. 125 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Height/2+m_lineWidth/2+1),
  126. 126 new Point(m_drawRect.Left+m_lineWidth/2, m_drawRect.Height/2+1)
  127. 127 });
  128. 128 path.CloseAllFigures();
  129. 129 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  130. 130 }
  131. 131 }
  132. 132 }

完工,看下完整代码和效果

  1. 1 using System;
  2. 2 using System.Collections.Generic;
  3. 3 using System.Linq;
  4. 4 using System.Text;
  5. 5 using System.Windows.Forms;
  6. 6 using System.Drawing;
  7. 7 using System.Drawing.Drawing2D;
  8. 8 using System.ComponentModel;
  9. 9
  10. 10 namespace HZH_Controls.Controls
  11. 11 {
  12. 12 /* 显示位置序号
  13. 13 * ****1***
  14. 14 * * *
  15. 15 * 6 2
  16. 16 * * *
  17. 17 * ****7***
  18. 18 * * *
  19. 19 * 5 3
  20. 20 * * *
  21. 21 * ****4***
  22. 22 */
  23. 23 public class UCLEDNum : UserControl
  24. 24 {
  25. 25 Rectangle m_drawRect = Rectangle.Empty;
  26. 26
  27. 27 private static Dictionary<char, int[]> m_nums = new Dictionary<char, int[]>();
  28. 28 static UCLEDNum()
  29. 29 {
  30. 30 m_nums['0'] = new int[] { 1, 2, 3, 4, 5, 6 };
  31. 31 m_nums['1'] = new int[] { 2, 3 };
  32. 32 m_nums['2'] = new int[] { 1, 2, 5, 4, 7 };
  33. 33 m_nums['3'] = new int[] { 1, 2, 7, 3, 4 };
  34. 34 m_nums['4'] = new int[] { 2, 3, 6, 7 };
  35. 35 m_nums['5'] = new int[] { 1, 6, 7, 3, 4 };
  36. 36 m_nums['6'] = new int[] { 1, 6, 5, 4, 3, 7 };
  37. 37 m_nums['7'] = new int[] { 1, 2, 3 };
  38. 38 m_nums['8'] = new int[] { 1, 2, 3, 4, 5, 6, 7 };
  39. 39 m_nums['9'] = new int[] { 1, 2, 3, 4, 7, 6 };
  40. 40 m_nums['-'] = new int[] { 7 };
  41. 41 m_nums[':'] = new int[0];
  42. 42 m_nums['.'] = new int[0];
  43. 43 }
  44. 44
  45. 45
  46. 46 public UCLEDNum()
  47. 47 {
  48. 48 SizeChanged += LEDNum_SizeChanged;
  49. 49 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
  50. 50 Size = new System.Drawing.Size(40, 70);
  51. 51 if (m_drawRect == Rectangle.Empty)
  52. 52 m_drawRect = new Rectangle(1, 1, this.Width - 2, this.Height - 2);
  53. 53 }
  54. 54
  55. 55 void LEDNum_SizeChanged(object sender, EventArgs e)
  56. 56 {
  57. 57 m_drawRect = new Rectangle(1, 1, this.Width - 2, this.Height - 2);
  58. 58 }
  59. 59
  60. 60 private char m_value = '0';
  61. 61
  62. 62 [Description(""), Category("自定义")]
  63. 63 public char Value
  64. 64 {
  65. 65 get { return m_value; }
  66. 66 set
  67. 67 {
  68. 68 if (!m_nums.ContainsKey(value))
  69. 69 {
  70. 70 return;
  71. 71 }
  72. 72 if (m_value != value)
  73. 73 {
  74. 74 m_value = value;
  75. 75 Refresh();
  76. 76 }
  77. 77 }
  78. 78 }
  79. 79
  80. 80 private int m_lineWidth = 8;
  81. 81
  82. 82 [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  83. 83 public int LineWidth
  84. 84 {
  85. 85 get { return m_lineWidth; }
  86. 86 set
  87. 87 {
  88. 88 m_lineWidth = value;
  89. 89 Refresh();
  90. 90 }
  91. 91 }
  92. 92
  93. 93 [Description("颜色"), Category("自定义")]
  94. 94 public override System.Drawing.Color ForeColor
  95. 95 {
  96. 96 get
  97. 97 {
  98. 98 return base.ForeColor;
  99. 99 }
  100. 100 set
  101. 101 {
  102. 102 base.ForeColor = value;
  103. 103 }
  104. 104 }
  105. 105
  106. 106 protected override void OnPaint(PaintEventArgs e)
  107. 107 {
  108. 108 base.OnPaint(e);
  109. 109 e.Graphics.SetGDIHigh();
  110. 110 if (m_value == '.')
  111. 111 {
  112. 112 Rectangle r2 = new Rectangle(m_drawRect.Left + (m_drawRect.Width - m_lineWidth) / 2, m_drawRect.Bottom - m_lineWidth * 2, m_lineWidth, m_lineWidth);
  113. 113 e.Graphics.FillRectangle(new SolidBrush(ForeColor), r2);
  114. 114 }
  115. 115 else if (m_value == ':')
  116. 116 {
  117. 117 Rectangle r1 = new Rectangle(m_drawRect.Left + (m_drawRect.Width - m_lineWidth) / 2, m_drawRect.Top + (m_drawRect.Height / 2 - m_lineWidth) / 2, m_lineWidth, m_lineWidth);
  118. 118 e.Graphics.FillRectangle(new SolidBrush(ForeColor), r1);
  119. 119 Rectangle r2 = new Rectangle(m_drawRect.Left + (m_drawRect.Width - m_lineWidth) / 2, m_drawRect.Top + (m_drawRect.Height / 2 - m_lineWidth) / 2 + m_drawRect.Height / 2, m_lineWidth, m_lineWidth);
  120. 120 e.Graphics.FillRectangle(new SolidBrush(ForeColor), r2);
  121. 121 }
  122. 122 else
  123. 123 {
  124. 124 int[] vs = m_nums[m_value];
  125. 125 if (vs.Contains(1))
  126. 126 {
  127. 127 GraphicsPath path = new GraphicsPath();
  128. 128 path.AddLines(new Point[]
  129. 129 {
  130. 130 new Point(m_drawRect.Left + 2, m_drawRect.Top),
  131. 131 new Point(m_drawRect.Right - 2, m_drawRect.Top),
  132. 132 new Point(m_drawRect.Right - m_lineWidth-2, m_drawRect.Top+m_lineWidth),
  133. 133 new Point(m_drawRect.Left + m_lineWidth+2, m_drawRect.Top+m_lineWidth),
  134. 134 new Point(m_drawRect.Left + 2, m_drawRect.Top)
  135. 135 });
  136. 136 path.CloseAllFigures();
  137. 137 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  138. 138 }
  139. 139
  140. 140 if (vs.Contains(2))
  141. 141 {
  142. 142 GraphicsPath path = new GraphicsPath();
  143. 143 path.AddLines(new Point[]
  144. 144 {
  145. 145 new Point(m_drawRect.Right, m_drawRect.Top),
  146. 146 new Point(m_drawRect.Right, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2),
  147. 147 new Point(m_drawRect.Right-m_lineWidth/2, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2+m_lineWidth/2),
  148. 148 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2),
  149. 149 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Top+m_lineWidth),
  150. 150 new Point(m_drawRect.Right, m_drawRect.Top)
  151. 151 });
  152. 152 path.CloseAllFigures();
  153. 153 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  154. 154 }
  155. 155
  156. 156 if (vs.Contains(3))
  157. 157 {
  158. 158 GraphicsPath path = new GraphicsPath();
  159. 159 path.AddLines(new Point[]
  160. 160 {
  161. 161 new Point(m_drawRect.Right, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  162. 162 new Point(m_drawRect.Right, m_drawRect.Bottom),
  163. 163 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Bottom-m_lineWidth),
  164. 164 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  165. 165 new Point(m_drawRect.Right-m_lineWidth/2, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2-m_lineWidth/2),
  166. 166 new Point(m_drawRect.Right, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  167. 167 });
  168. 168 path.CloseAllFigures();
  169. 169 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  170. 170 }
  171. 171
  172. 172 if (vs.Contains(4))
  173. 173 {
  174. 174 GraphicsPath path = new GraphicsPath();
  175. 175 path.AddLines(new Point[]
  176. 176 {
  177. 177 new Point(m_drawRect.Left + 2, m_drawRect.Bottom),
  178. 178 new Point(m_drawRect.Right - 2, m_drawRect.Bottom),
  179. 179 new Point(m_drawRect.Right - m_lineWidth-2, m_drawRect.Bottom-m_lineWidth),
  180. 180 new Point(m_drawRect.Left + m_lineWidth+2, m_drawRect.Bottom-m_lineWidth),
  181. 181 new Point(m_drawRect.Left + 2, m_drawRect.Bottom)
  182. 182 });
  183. 183 path.CloseAllFigures();
  184. 184 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  185. 185 }
  186. 186
  187. 187 if (vs.Contains(5))
  188. 188 {
  189. 189 GraphicsPath path = new GraphicsPath();
  190. 190 path.AddLines(new Point[]
  191. 191 {
  192. 192 new Point(m_drawRect.Left, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  193. 193 new Point(m_drawRect.Left, m_drawRect.Bottom),
  194. 194 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Bottom-m_lineWidth),
  195. 195 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  196. 196 new Point(m_drawRect.Left+m_lineWidth/2, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2-m_lineWidth/2),
  197. 197 new Point(m_drawRect.Left, m_drawRect.Bottom-(m_drawRect.Height-m_lineWidth-4)/2),
  198. 198 });
  199. 199 path.CloseAllFigures();
  200. 200 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  201. 201 }
  202. 202
  203. 203
  204. 204 if (vs.Contains(6))
  205. 205 {
  206. 206 GraphicsPath path = new GraphicsPath();
  207. 207 path.AddLines(new Point[]
  208. 208 {
  209. 209 new Point(m_drawRect.Left, m_drawRect.Top),
  210. 210 new Point(m_drawRect.Left, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2),
  211. 211 new Point(m_drawRect.Left+m_lineWidth/2, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2+m_lineWidth/2),
  212. 212 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Top+(m_drawRect.Height-m_lineWidth-4)/2),
  213. 213 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Top+m_lineWidth),
  214. 214 new Point(m_drawRect.Left, m_drawRect.Top)
  215. 215 });
  216. 216 path.CloseAllFigures();
  217. 217 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  218. 218 }
  219. 219
  220. 220 if (vs.Contains(7))
  221. 221 {
  222. 222 GraphicsPath path = new GraphicsPath();
  223. 223 path.AddLines(new Point[]
  224. 224 {
  225. 225 new Point(m_drawRect.Left+m_lineWidth/2, m_drawRect.Height/2+1),
  226. 226 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Height/2-m_lineWidth/2+1),
  227. 227 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Height/2-m_lineWidth/2+1),
  228. 228 new Point(m_drawRect.Right-m_lineWidth/2, m_drawRect.Height/2+1),
  229. 229 new Point(m_drawRect.Right-m_lineWidth, m_drawRect.Height/2+m_lineWidth/2+1),
  230. 230 new Point(m_drawRect.Left+m_lineWidth, m_drawRect.Height/2+m_lineWidth/2+1),
  231. 231 new Point(m_drawRect.Left+m_lineWidth/2, m_drawRect.Height/2+1)
  232. 232 });
  233. 233 path.CloseAllFigures();
  234. 234 e.Graphics.FillPath(new SolidBrush(ForeColor), path);
  235. 235 }
  236. 236 }
  237. 237 }
  238. 238 }
  239. 239 }

View Code

 

 

 以上就是单个字符的了

 

=======================分割线==========================

下面对数字控件处理

添加一个用户控件UCLEDNums

添加一点属性

  1. 1 private string m_value;
  2. 2
  3. 3 [Description(""), Category("自定义")]
  4. 4 public string Value
  5. 5 {
  6. 6 get { return m_value; }
  7. 7 set
  8. 8 {
  9. 9 m_value = value;
  10. 10 ReloadValue();
  11. 11 }
  12. 12 }
  13. 13
  14. 14 private int m_lineWidth = 8;
  15. 15
  16. 16 [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  17. 17 public int LineWidth
  18. 18 {
  19. 19 get { return m_lineWidth; }
  20. 20 set
  21. 21 {
  22. 22 m_lineWidth = value;
  23. 23 foreach (UCLEDNum c in this.Controls)
  24. 24 {
  25. 25 c.LineWidth = value;
  26. 26 }
  27. 27 }
  28. 28 }
  29. 29
  30. 30 [Description("颜色"), Category("自定义")]
  31. 31 public override System.Drawing.Color ForeColor
  32. 32 {
  33. 33 get
  34. 34 {
  35. 35 return base.ForeColor;
  36. 36 }
  37. 37 set
  38. 38 {
  39. 39 base.ForeColor = value;
  40. 40 foreach (UCLEDNum c in this.Controls)
  41. 41 {
  42. 42 c.ForeColor = value;
  43. 43 }
  44. 44 }
  45. 45 }
  46. 46
  47. 47 public override RightToLeft RightToLeft
  48. 48 {
  49. 49 get
  50. 50 {
  51. 51 return base.RightToLeft;
  52. 52 }
  53. 53 set
  54. 54 {
  55. 55 base.RightToLeft = value;
  56. 56 ReloadValue();
  57. 57 }
  58. 58 }

加载控件的函数

  1. 1 private void ReloadValue()
  2. 2 {
  3. 3 try
  4. 4 {
  5. 5 ControlHelper.FreezeControl(this, true);
  6. 6 this.Controls.Clear();
  7. 7 foreach (var item in m_value)
  8. 8 {
  9. 9 UCLEDNum uc = new UCLEDNum();
  10. 10 if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
  11. 11 uc.Dock = DockStyle.Right;
  12. 12 else
  13. 13 uc.Dock = DockStyle.Left;
  14. 14 uc.Value = item;
  15. 15 uc.ForeColor = ForeColor;
  16. 16 uc.LineWidth = m_lineWidth;
  17. 17 this.Controls.Add(uc);
  18. 18 if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
  19. 19 uc.SendToBack();
  20. 20 else
  21. 21 uc.BringToFront();
  22. 22 }
  23. 23 }
  24. 24 finally
  25. 25 {
  26. 26 ControlHelper.FreezeControl(this, false);
  27. 27 }
  28. 28 }

完整代码及效果

  1. 1 using System;
  2. 2 using System.Collections.Generic;
  3. 3 using System.ComponentModel;
  4. 4 using System.Drawing;
  5. 5 using System.Data;
  6. 6 using System.Linq;
  7. 7 using System.Text;
  8. 8 using System.Windows.Forms;
  9. 9
  10. 10 namespace HZH_Controls.Controls.LED
  11. 11 {
  12. 12 public partial class UCLEDNums : UserControl
  13. 13 {
  14. 14 private string m_value;
  15. 15
  16. 16 [Description(""), Category("自定义")]
  17. 17 public string Value
  18. 18 {
  19. 19 get { return m_value; }
  20. 20 set
  21. 21 {
  22. 22 m_value = value;
  23. 23 ReloadValue();
  24. 24 }
  25. 25 }
  26. 26
  27. 27 private int m_lineWidth = 8;
  28. 28
  29. 29 [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  30. 30 public int LineWidth
  31. 31 {
  32. 32 get { return m_lineWidth; }
  33. 33 set
  34. 34 {
  35. 35 m_lineWidth = value;
  36. 36 foreach (UCLEDNum c in this.Controls)
  37. 37 {
  38. 38 c.LineWidth = value;
  39. 39 }
  40. 40 }
  41. 41 }
  42. 42
  43. 43 [Description("颜色"), Category("自定义")]
  44. 44 public override System.Drawing.Color ForeColor
  45. 45 {
  46. 46 get
  47. 47 {
  48. 48 return base.ForeColor;
  49. 49 }
  50. 50 set
  51. 51 {
  52. 52 base.ForeColor = value;
  53. 53 foreach (UCLEDNum c in this.Controls)
  54. 54 {
  55. 55 c.ForeColor = value;
  56. 56 }
  57. 57 }
  58. 58 }
  59. 59
  60. 60 public override RightToLeft RightToLeft
  61. 61 {
  62. 62 get
  63. 63 {
  64. 64 return base.RightToLeft;
  65. 65 }
  66. 66 set
  67. 67 {
  68. 68 base.RightToLeft = value;
  69. 69 ReloadValue();
  70. 70 }
  71. 71 }
  72. 72
  73. 73 private void ReloadValue()
  74. 74 {
  75. 75 try
  76. 76 {
  77. 77 ControlHelper.FreezeControl(this, true);
  78. 78 this.Controls.Clear();
  79. 79 foreach (var item in m_value)
  80. 80 {
  81. 81 UCLEDNum uc = new UCLEDNum();
  82. 82 if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
  83. 83 uc.Dock = DockStyle.Right;
  84. 84 else
  85. 85 uc.Dock = DockStyle.Left;
  86. 86 uc.Value = item;
  87. 87 uc.ForeColor = ForeColor;
  88. 88 uc.LineWidth = m_lineWidth;
  89. 89 this.Controls.Add(uc);
  90. 90 if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
  91. 91 uc.SendToBack();
  92. 92 else
  93. 93 uc.BringToFront();
  94. 94 }
  95. 95 }
  96. 96 finally
  97. 97 {
  98. 98 ControlHelper.FreezeControl(this, false);
  99. 99 }
  100. 100 }
  101. 101 public UCLEDNums()
  102. 102 {
  103. 103 InitializeComponent();
  104. 104 Value = "0.00";
  105. 105 }
  106. 106 }
  107. 107 }

View Code

  1. 1 namespace HZH_Controls.Controls.LED
  2. 2 {
  3. 3 partial class UCLEDNums
  4. 4 {
  5. 5 /// <summary>
  6. 6 /// 必需的设计器变量。
  7. 7 /// </summary>
  8. 8 private System.ComponentModel.IContainer components = null;
  9. 9
  10. 10 /// <summary>
  11. 11 /// 清理所有正在使用的资源。
  12. 12 /// </summary>
  13. 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
  14. 14 protected override void Dispose(bool disposing)
  15. 15 {
  16. 16 if (disposing && (components != null))
  17. 17 {
  18. 18 components.Dispose();
  19. 19 }
  20. 20 base.Dispose(disposing);
  21. 21 }
  22. 22
  23. 23 #region 组件设计器生成的代码
  24. 24
  25. 25 /// <summary>
  26. 26 /// 设计器支持所需的方法 - 不要
  27. 27 /// 使用代码编辑器修改此方法的内容。
  28. 28 /// </summary>
  29. 29 private void InitializeComponent()
  30. 30 {
  31. 31 this.SuspendLayout();
  32. 32 //
  33. 33 // UCLEDNums
  34. 34 //
  35. 35 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  36. 36 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  37. 37 this.Name = "UCLEDNums";
  38. 38 this.Size = new System.Drawing.Size(150, 58);
  39. 39 this.ResumeLayout(false);
  40. 40
  41. 41 }
  42. 42
  43. 43 #endregion
  44. 44 }
  45. 45 }

View Code

 

 

 =======================分割线==========================

下面是日期类控件了,这里偷懒,分成3个控件,分别是日期控件,时间控件,日期时间控件

先说日期控件,

添加一个用户控件UCLEDData

添加属性

  1. 1 private DateTime m_value;
  2. 2
  3. 3 [Description(""), Category("自定义")]
  4. 4 public DateTime Value
  5. 5 {
  6. 6 get { return m_value; }
  7. 7 set
  8. 8 {
  9. 9 m_value = value;
  10. 10 string str = value.ToString("yyyy-MM-dd");
  11. 11 for (int i = 0; i < str.Length; i++)
  12. 12 {
  13. 13 ((UCLEDNum)this.tableLayoutPanel1.Controls.Find("D" + (i + 1), false)[0]).Value = str[i];
  14. 14 }
  15. 15 }
  16. 16 }
  17. 17
  18. 18 private int m_lineWidth = 8;
  19. 19
  20. 20 [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  21. 21 public int LineWidth
  22. 22 {
  23. 23 get { return m_lineWidth; }
  24. 24 set
  25. 25 {
  26. 26 m_lineWidth = value;
  27. 27 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
  28. 28 {
  29. 29 c.LineWidth = value;
  30. 30 }
  31. 31 }
  32. 32 }
  33. 33
  34. 34 [Description("颜色"), Category("自定义")]
  35. 35 public override System.Drawing.Color ForeColor
  36. 36 {
  37. 37 get
  38. 38 {
  39. 39 return base.ForeColor;
  40. 40 }
  41. 41 set
  42. 42 {
  43. 43 base.ForeColor = value;
  44. 44 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
  45. 45 {
  46. 46 c.ForeColor = value;
  47. 47 }
  48. 48 }
  49. 49 }

完整代码

  1. 1 using System;
  2. 2 using System.Collections.Generic;
  3. 3 using System.ComponentModel;
  4. 4 using System.Drawing;
  5. 5 using System.Data;
  6. 6 using System.Linq;
  7. 7 using System.Text;
  8. 8 using System.Windows.Forms;
  9. 9
  10. 10 namespace HZH_Controls.Controls
  11. 11 {
  12. 12 public partial class UCLEDData : UserControl
  13. 13 {
  14. 14 private DateTime m_value;
  15. 15
  16. 16 [Description(""), Category("自定义")]
  17. 17 public DateTime Value
  18. 18 {
  19. 19 get { return m_value; }
  20. 20 set
  21. 21 {
  22. 22 m_value = value;
  23. 23 string str = value.ToString("yyyy-MM-dd");
  24. 24 for (int i = 0; i < str.Length; i++)
  25. 25 {
  26. 26 ((UCLEDNum)this.tableLayoutPanel1.Controls.Find("D" + (i + 1), false)[0]).Value = str[i];
  27. 27 }
  28. 28 }
  29. 29 }
  30. 30
  31. 31 private int m_lineWidth = 8;
  32. 32
  33. 33 [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  34. 34 public int LineWidth
  35. 35 {
  36. 36 get { return m_lineWidth; }
  37. 37 set
  38. 38 {
  39. 39 m_lineWidth = value;
  40. 40 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
  41. 41 {
  42. 42 c.LineWidth = value;
  43. 43 }
  44. 44 }
  45. 45 }
  46. 46
  47. 47 [Description("颜色"), Category("自定义")]
  48. 48 public override System.Drawing.Color ForeColor
  49. 49 {
  50. 50 get
  51. 51 {
  52. 52 return base.ForeColor;
  53. 53 }
  54. 54 set
  55. 55 {
  56. 56 base.ForeColor = value;
  57. 57 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
  58. 58 {
  59. 59 c.ForeColor = value;
  60. 60 }
  61. 61 }
  62. 62 }
  63. 63 public UCLEDData()
  64. 64 {
  65. 65 InitializeComponent();
  66. 66 Value = DateTime.Now;
  67. 67 }
  68. 68 }
  69. 69 }

View Code

  1. 1 namespace HZH_Controls.Controls
  2. 2 {
  3. 3 partial class UCLEDData
  4. 4 {
  5. 5 /// <summary>
  6. 6 /// 必需的设计器变量。
  7. 7 /// </summary>
  8. 8 private System.ComponentModel.IContainer components = null;
  9. 9
  10. 10 /// <summary>
  11. 11 /// 清理所有正在使用的资源。
  12. 12 /// </summary>
  13. 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
  14. 14 protected override void Dispose(bool disposing)
  15. 15 {
  16. 16 if (disposing && (components != null))
  17. 17 {
  18. 18 components.Dispose();
  19. 19 }
  20. 20 base.Dispose(disposing);
  21. 21 }
  22. 22
  23. 23 #region 组件设计器生成的代码
  24. 24
  25. 25 /// <summary>
  26. 26 /// 设计器支持所需的方法 - 不要
  27. 27 /// 使用代码编辑器修改此方法的内容。
  28. 28 /// </summary>
  29. 29 private void InitializeComponent()
  30. 30 {
  31. 31 this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
  32. 32 this.D1 = new HZH_Controls.Controls.UCLEDNum();
  33. 33 this.D2 = new HZH_Controls.Controls.UCLEDNum();
  34. 34 this.D3 = new HZH_Controls.Controls.UCLEDNum();
  35. 35 this.D4 = new HZH_Controls.Controls.UCLEDNum();
  36. 36 this.D5 = new HZH_Controls.Controls.UCLEDNum();
  37. 37 this.D6 = new HZH_Controls.Controls.UCLEDNum();
  38. 38 this.D7 = new HZH_Controls.Controls.UCLEDNum();
  39. 39 this.D8 = new HZH_Controls.Controls.UCLEDNum();
  40. 40 this.D9 = new HZH_Controls.Controls.UCLEDNum();
  41. 41 this.D10 = new HZH_Controls.Controls.UCLEDNum();
  42. 42 this.tableLayoutPanel1.SuspendLayout();
  43. 43 this.SuspendLayout();
  44. 44 //
  45. 45 // tableLayoutPanel1
  46. 46 //
  47. 47 this.tableLayoutPanel1.ColumnCount = 10;
  48. 48 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  49. 49 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  50. 50 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  51. 51 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  52. 52 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  53. 53 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  54. 54 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  55. 55 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  56. 56 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  57. 57 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
  58. 58 this.tableLayoutPanel1.Controls.Add(this.D1, 0, 0);
  59. 59 this.tableLayoutPanel1.Controls.Add(this.D2, 1, 0);
  60. 60 this.tableLayoutPanel1.Controls.Add(this.D3, 2, 0);
  61. 61 this.tableLayoutPanel1.Controls.Add(this.D4, 3, 0);
  62. 62 this.tableLayoutPanel1.Controls.Add(this.D5, 4, 0);
  63. 63 this.tableLayoutPanel1.Controls.Add(this.D6, 5, 0);
  64. 64 this.tableLayoutPanel1.Controls.Add(this.D7, 6, 0);
  65. 65 this.tableLayoutPanel1.Controls.Add(this.D8, 7, 0);
  66. 66 this.tableLayoutPanel1.Controls.Add(this.D9, 8, 0);
  67. 67 this.tableLayoutPanel1.Controls.Add(this.D10, 9, 0);
  68. 68 this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
  69. 69 this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
  70. 70 this.tableLayoutPanel1.Name = "tableLayoutPanel1";
  71. 71 this.tableLayoutPanel1.RowCount = 1;
  72. 72 this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
  73. 73 this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
  74. 74 this.tableLayoutPanel1.Size = new System.Drawing.Size(360, 58);
  75. 75 this.tableLayoutPanel1.TabIndex = 0;
  76. 76 //
  77. 77 // D1
  78. 78 //
  79. 79 this.D1.Dock = System.Windows.Forms.DockStyle.Fill;
  80. 80 this.D1.LineWidth = 8;
  81. 81 this.D1.Location = new System.Drawing.Point(3, 3);
  82. 82 this.D1.Name = "D1";
  83. 83 this.D1.Size = new System.Drawing.Size(30, 52);
  84. 84 this.D1.TabIndex = 0;
  85. 85 this.D1.Value = '2';
  86. 86 //
  87. 87 // D2
  88. 88 //
  89. 89 this.D2.Dock = System.Windows.Forms.DockStyle.Fill;
  90. 90 this.D2.LineWidth = 8;
  91. 91 this.D2.Location = new System.Drawing.Point(39, 3);
  92. 92 this.D2.Name = "D2";
  93. 93 this.D2.Size = new System.Drawing.Size(30, 52);
  94. 94 this.D2.TabIndex = 1;
  95. 95 this.D2.Value = '0';
  96. 96 //
  97. 97 // D3
  98. 98 //
  99. 99 this.D3.Dock = System.Windows.Forms.DockStyle.Fill;
  100. 100 this.D3.LineWidth = 8;
  101. 101 this.D3.Location = new System.Drawing.Point(75, 3);
  102. 102 this.D3.Name = "D3";
  103. 103 this.D3.Size = new System.Drawing.Size(30, 52);
  104. 104 this.D3.TabIndex = 2;
  105. 105 this.D3.Value = '1';
  106. 106 //
  107. 107 // D4
  108. 108 //
  109. 109 this.D4.Dock = System.Windows.Forms.DockStyle.Fill;
  110. 110 this.D4.LineWidth = 8;
  111. 111 this.D4.Location = new System.Drawing.Point(111, 3);
  112. 112 this.D4.Name = "D4";
  113. 113 this.D4.Size = new System.Drawing.Size(30, 52);
  114. 114 this.D4.TabIndex = 3;
  115. 115 this.D4.Value = '9';
  116. 116 //
  117. 117 // D5
  118. 118 //
  119. 119 this.D5.Dock = System.Windows.Forms.DockStyle.Fill;
  120. 120 this.D5.LineWidth = 8;
  121. 121 this.D5.Location = new System.Drawing.Point(147, 3);
  122. 122 this.D5.Name = "D5";
  123. 123 this.D5.Size = new System.Drawing.Size(30, 52);
  124. 124 this.D5.TabIndex = 4;
  125. 125 this.D5.Value = '-';
  126. 126 //
  127. 127 // D6
  128. 128 //
  129. 129 this.D6.Dock = System.Windows.Forms.DockStyle.Fill;
  130. 130 this.D6.LineWidth = 8;
  131. 131 this.D6.Location = new System.Drawing.Point(183, 3);
  132. 132 this.D6.Name = "D6";
  133. 133 this.D6.Size = new System.Drawing.Size(30, 52);
  134. 134 this.D6.TabIndex = 5;
  135. 135 this.D6.Value = '0';
  136. 136 //
  137. 137 // D7
  138. 138 //
  139. 139 this.D7.Dock = System.Windows.Forms.DockStyle.Fill;
  140. 140 this.D7.LineWidth = 8;
  141. 141 this.D7.Location = new System.Drawing.Point(219, 3);
  142. 142 this.D7.Name = "D7";
  143. 143 this.D7.Size = new System.Drawing.Size(30, 52);
  144. 144 this.D7.TabIndex = 6;
  145. 145 this.D7.Value = '8';
  146. 146 //
  147. 147 // D8
  148. 148 //
  149. 149 this.D8.Dock = System.Windows.Forms.DockStyle.Fill;
  150. 150 this.D8.LineWidth = 8;
  151. 151 this.D8.Location = new System.Drawing.Point(255, 3);
  152. 152 this.D8.Name = "D8";
  153. 153 this.D8.Size = new System.Drawing.Size(30, 52);
  154. 154 this.D8.TabIndex = 7;
  155. 155 this.D8.Value = '-';
  156. 156 //
  157. 157 // D9
  158. 158 //
  159. 159 this.D9.Dock = System.Windows.Forms.DockStyle.Fill;
  160. 160 this.D9.LineWidth = 8;
  161. 161 this.D9.Location = new System.Drawing.Point(291, 3);
  162. 162 this.D9.Name = "D9";
  163. 163 this.D9.Size = new System.Drawing.Size(30, 52);
  164. 164 this.D9.TabIndex = 8;
  165. 165 this.D9.Value = '0';
  166. 166 //
  167. 167 // D10
  168. 168 //
  169. 169 this.D10.Dock = System.Windows.Forms.DockStyle.Fill;
  170. 170 this.D10.LineWidth = 8;
  171. 171 this.D10.Location = new System.Drawing.Point(327, 3);
  172. 172 this.D10.Name = "D10";
  173. 173 this.D10.Size = new System.Drawing.Size(30, 52);
  174. 174 this.D10.TabIndex = 9;
  175. 175 this.D10.Value = '1';
  176. 176 //
  177. 177 // UCLEDData
  178. 178 //
  179. 179 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
  180. 180 this.Controls.Add(this.tableLayoutPanel1);
  181. 181 this.Margin = new System.Windows.Forms.Padding(0);
  182. 182 this.Name = "UCLEDData";
  183. 183 this.Size = new System.Drawing.Size(360, 58);
  184. 184 this.tableLayoutPanel1.ResumeLayout(false);
  185. 185 this.ResumeLayout(false);
  186. 186
  187. 187 }
  188. 188
  189. 189 #endregion
  190. 190
  191. 191 private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
  192. 192 private UCLEDNum D1;
  193. 193 private UCLEDNum D2;
  194. 194 private UCLEDNum D3;
  195. 195 private UCLEDNum D4;
  196. 196 private UCLEDNum D5;
  197. 197 private UCLEDNum D6;
  198. 198 private UCLEDNum D7;
  199. 199 private UCLEDNum D8;
  200. 200 private UCLEDNum D9;
  201. 201 private UCLEDNum D10;
  202. 202
  203. 203 }
  204. 204 }

View Code

 =======================分割线==========================

时间控件

添加一个用户控件UCLEDTime

添加属性

  1. 1 private DateTime m_value;
  2. 2
  3. 3 [Description(""), Category("自定义")]
  4. 4 public DateTime Value
  5. 5 {
  6. 6 get { return m_value; }
  7. 7 set
  8. 8 {
  9. 9 m_value = value;
  10. 10 string str = value.ToString("HH:mm:ss");
  11. 11 for (int i = 0; i < str.Length; i++)
  12. 12 {
  13. 13 ((UCLEDNum)this.tableLayoutPanel1.Controls.Find("D" + (i + 1), false)[0]).Value = str[i];
  14. 14 }
  15. 15 }
  16. 16 }
  17. 17
  18. 18 private int m_lineWidth = 8;
  19. 19
  20. 20 [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  21. 21 public int LineWidth
  22. 22 {
  23. 23 get { return m_lineWidth; }
  24. 24 set
  25. 25 {
  26. 26 m_lineWidth = value;
  27. 27 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
  28. 28 {
  29. 29 c.LineWidth = value;
  30. 30 }
  31. 31 }
  32. 32 }
  33. 33
  34. 34 [Description("颜色"), Category("自定义")]
  35. 35 public override System.Drawing.Color ForeColor
  36. 36 {
  37. 37 get
  38. 38 {
  39. 39 return base.ForeColor;
  40. 40 }
  41. 41 set
  42. 42 {
  43. 43 base.ForeColor = value;
  44. 44 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
  45. 45 {
  46. 46 c.ForeColor = value;
  47. 47 }
  48. 48 }
  49. 49 }

全部代码

  1. 1 using System;
  2. 2 using System.Collections.Generic;
  3. 3 using System.ComponentModel;
  4. 4 using System.Drawing;
  5. 5 using System.Data;
  6. 6 using System.Linq;
  7. 7 using System.Text;
  8. 8 using System.Windows.Forms;
  9. 9
  10. 10 namespace HZH_Controls.Controls
  11. 11 {
  12. 12 public partial class UCLEDTime : UserControl
  13. 13 {
  14. 14 private DateTime m_value;
  15. 15
  16. 16 [Description(""), Category("自定义")]
  17. 17 public DateTime Value
  18. 18 {
  19. 19 get { return m_value; }
  20. 20 set
  21. 21 {
  22. 22 m_value = value;
  23. 23 string str = value.ToString("HH:mm:ss");
  24. 24 for (int i = 0; i < str.Length; i++)
  25. 25 {
  26. 26 ((UCLEDNum)this.tableLayoutPanel1.Controls.Find("D" + (i + 1), false)[0]).Value = str[i];
  27. 27 }
  28. 28 }
  29. 29 }
  30. 30
  31. 31 private int m_lineWidth = 8;
  32. 32
  33. 33 [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
  34. 34 public int LineWidth
  35. 35 {
  36. 36 get { return m_lineWidth; }
  37. 37 set
  38. 38 {
  39. 39 m_lineWidth = value;
  40. 40 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
  41. 41 {
  42. 42 c.LineWidth = value;
  43. 43 }
  44. 44 }
  45. 45 }
  46. 46
  47. 47 [Description("颜色"), Category("自定义")]
  48. 48 public override System.Drawing.Color ForeColor
  49. 49 {
  50. 50 get
  51. 51 {
  52. 52 return base.ForeColor;
  53. 53 }
  54. 54 set
  55. 55 {
  56. 56 base.ForeColor = value;
  57. 57 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
  58. 58 {
  59. 59 c.ForeColor = value;
  60. 60 }
  61. 61 }
  62. 62 }
  63. 63 public UCLEDTime()
  64. 64 {
  65. 65 InitializeComponent();
  66. 66 Value = DateTime.Now;
  67. 67 }
  68. 68 }
  69. 69 }

View Code

  1. 1 namespace HZH_Controls.Controls
  2. 2 {
  3. 3 partial class UCLEDTime
  4. 4 {
  5. 5 /// <summary>
  6. 6 /// 必需的设计器变量。
  7. 7 /// </summary>
  8. 8 private System.ComponentModel.IContainer components = null;
  9. 9
  10. 10 /// <summary>
  11. 11 /// 清理所有正在使用的资源。
  12. 12 /// </summary>
  13. 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
  14. 14 protected override void Dispose(bool disposing)
  15. 15 {
  16. 16 if (disposing && (components != null))
  17. 17 {
  18. 18 components.Dispose();
  19. 19 }
  20. 20 base.Dispose(disposing);
  21. 21 }
  22. 22
  23. 23 #region 组件设计器生成的代码
  24. 24
  25. 25 /// <summary>
  26. 26 /// 设计器支持所需的方法 - 不要
  27. 27 /// 使用代码编辑器修改此方法的内容。
  28. 28 /// </summary>
  29. 29 private void InitializeComponent()
  30. 30 {
  31. 31 this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
  32. 32 this.D1 = new HZH_Controls.Controls.UCLEDNum();
  33. 33 this.D2 = new HZH_Controls.Controls.UCLEDNum();
  34. 34 this.D3 = new HZH_Controls.Controls.UCLEDNum();
  35. 35 this.D4 = new HZH_Controls.Controls.UCLEDNum();
  36. 36 this.D5 = new HZH_Controls.Controls.UCLEDNum();
  37. 37 this.D6 = new HZH_Controls.Controls.UCLEDNum();
  38. 38 this.D7 = new HZH_Controls.Controls.UCLEDNum();
  39. 39 this.D8 = new HZH_Controls.Controls.UCLEDNum();
  40. 40 this.tableLayoutPanel1.SuspendLayout();
  41. 41 this.SuspendLayout();
  42. 42 //
  43. 43 // tableLayoutPanel1
  44. 44 //
  45. 45 this.tableLayoutPanel1.ColumnCount = 8;
  46. 46 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.5F));
  47. 47 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.5F));
  48. 48 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.5F));
  49. 49 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.5F));
  50. 50 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.5F));
  51. 51 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.5F));
  52. 52 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.5F));
  53. 53 this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.5F));
  54. 54 this.tableLayoutPanel1.Controls.Add(this.D1, 0, 0);
  55. 55 this.tableLayoutPanel1.Controls.Add(this.D2, 1, 0);
  56. 56 this.tableLayoutPanel1.Controls.Add(this.D3, 2, 0);
  57. 57 this.tableLayoutPanel1.Controls.Add(this.D4, 3, 0);
  58. 58 this.tableLayoutPanel1.Controls.Add(this.D5, 4, 0);
  59. 59 this.tableLayoutPanel1.Controls.Add(this.D6, 5, 0);
  60. 60 this.tableLayoutPanel1.Controls.Add(this.D7, 6, 0);
  61. 61 this.tableLayoutPanel1.Controls.Add(this.D8, 7, 0);
  62. 62 this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
  63. 63 this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
  64. 64 this.tableLayoutPanel1.Name = "tableLayoutPanel1";
  65. 65 this.tableLayoutPanel1.RowCount = 1;
  66. 66 this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
  67. 67 this.tableLayoutPanel1.Size = new System.Drawing.Size(290, 58);
  68. 68 this.tableLayoutPanel1.TabIndex = 0;
  69. 69 //
  70. 70 // D1
  71. 71 //
  72. 72 this.D1.Dock = System.Windows.Forms.DockStyle.Fill;
  73. 73 this.D1.LineWidth = 8;
  74. 74 this.D1.Location = new System.Drawing.Point(3, 3);
  75. 75 this.D1.Name = "D1";
  76. 76 this.D1.Size = new System.Drawing.Size(30, 52);
  77. 77 this.D1.TabIndex = 0;
  78. 78 this.D1.Value = '2';
  79. 79 //
  80. 80 // D2
  81. 81 //
  82. 82 this.D2.Dock = System.Windows.Forms.DockStyle.Fill;
  83. 83 this.D2.LineWidth = 8;
  84. 84 this.D2.Location = new System.Drawing.Point(39, 3);
  85. 85 this.D2.Name = "D2";
  86. 86 this.D2.Size = new System.Drawing.Size(30, 52);
  87. 87 this.D2.TabIndex = 1;
  88. 88 this.D2.Value = '3';
  89. 89 //
  90. 90 // D3
  91. 91 //
  92. 92 this.D3.Dock = System.Windows.Forms.DockStyle.Fill;
  93. 93 this.D3.LineWidth = 8;
  94. 94 this.D3.Location = new System.Drawing.Point(75, 3);
  95. 95 this.D3.Name = "D3";
  96. 96 this.D3.Size = new System.Drawing.Size(30, 52);
  97. 97 this.D3.TabIndex = 2;
  98. 98 this.D3.Value = ':';
  99. 99 //
  100. 100 // D4
  101. 101 //
  102. 102 this.D4.Dock = System.Windows.Forms.DockStyle.Fill;
  103. 103 this.D4.LineWidth = 8;
  104. 104 this.D4.Location = new System.Drawing.Point(111, 3);
  105. 105 this.D4.Name = "D4";
  106. 106 this.D4.Size = new System.Drawing.Size(30, 52);
  107. 107 this.D4.TabIndex = 3;
  108. 108 this.D4.Value = '1';
  109. 109 //
  110. 110 // D5
  111. 111 //
  112. 112 this.D5.Dock = System.Windows.Forms.DockStyle.Fill;
  113. 113 this.D5.LineWidth = 8;
  114. 114 this.D5.Location = new System.Drawing.Point(147, 3);
  115. 115 this.D5.Name = "D5";
  116. 116 this.D5.Size = new System.Drawing.Size(30, 52);
  117. 117 this.D5.TabIndex = 4;
  118. 118 this.D5.Value = '0';
  119. 119 //
  120. 120 // D6
  121. 121 //
  122. 122 this.D6.Dock = System.Windows.Forms.DockStyle.Fill;
  123. 123 this.D6.LineWidth = 8;
  124. 124 this.D6.Location = new System.Drawing.Point(183, 3);
  125. 125 this.D6.Name = "D6";
  126. 126 this.D6.Size = new System.Drawing.Size(30, 52);
  127. 127 this.D6.TabIndex = 5;
  128. 128 this.D6.Value = ':';
  129. 129 //
  130. 130 // D7
  131. 131 //
  132. 132 this.D7.Dock = System.Windows.Forms.DockStyle.Fill;
  133. 133 this.D7.LineWidth = 8;
  134. 134 this.D7.Location = new System.Drawing.Point(219, 3);
  135. 135 this.D7.Name = "D7";
  136. 136 this.D7.Size = new System.Drawing.Size(30, 52);
  137. 137 this.D7.TabIndex = 6;
  138. 138 this.D7.Value = '1';
  139. 139 //
  140. 140 // D8
  141. 141 //
  142. 142 this.D8.Dock = System.Windows.Forms.DockStyle.Fill;
  143. 143 this.D8.LineWidth = 8;
  144. 144 this.D8.Location = new System.Drawing.Point(255, 3);
  145. 145 this.D8.Name = "D8";
  146. 146 this.D8.Size = new System.Drawing.Size(32, 52);
  147. 147 this.D8.TabIndex = 7;
  148. 148 this.D8.Value = '0';
  149. 149 //
  150. 150 // UCLEDTime
  151. 151 //
  152. 152 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
  153. 153 this.Controls.Add(this.tableLayoutPanel1);
  154. 154 this.Name = "UCLEDTime";
  155. 155 this.Size = new System.Drawing.Size(290, 58);
  156. 156 this.tableLayoutPanel1.ResumeLayout(false);
  157. 157 this.ResumeLayout(false);
  158. 158
  159. 159 }
  160. 160
  161. 161 #endregion
  162. 162
  163. 163 private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
  164. 164 private UCLEDNum D1;
  165. 165 private UCLEDNum D2;
  166. 166 private UCLEDNum D3;
  167. 167 private UCLEDNum D4;
  168. 168 private UCLEDNum D5;
  169. 169 private UCLEDNum D6;
  170. 170 private UCLEDNum D7;
  171. 171 private UCLEDNum D8;
  172. 172 }
  173. 173 }

View Code

 =======================分割线==========================

日期时间控件

添加一个用户控件UCLEDDataTime

添加属性

 1  private DateTime m_value;
 2 
 3         [Description(""), Category("自定义")]
 4         public DateTime Value
 5         {
 6             get { return m_value; }
 7             set
 8             {
 9                 m_value = value;
10                 string str = value.ToString("yyyy-MM-dd HH:mm:ss");
11                 for (int i = 0; i < str.Length; i++)
12                 {
13                     if (i == 10)
14                         continue;
15                     ((UCLEDNum)this.tableLayoutPanel1.Controls.Find("D" + (i + 1), false)[0]).Value = str[i];
16                 }
17             }
18         }
19 
20         private int m_lineWidth = 8;
21 
22         [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
23         public int LineWidth
24         {
25             get { return m_lineWidth; }
26             set
27             {
28                 m_lineWidth = value;
29                 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
30                 {
31                     c.LineWidth = value;
32                 }
33             }
34         }
35 
36         [Description("颜色"), Category("自定义")]
37         public override System.Drawing.Color ForeColor
38         {
39             get
40             {
41                 return base.ForeColor;
42             }
43             set
44             {
45                 base.ForeColor = value;
46                 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
47                 {
48                     c.ForeColor = value;
49                 }
50             }
51         }

全部代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Drawing;
 5 using System.Data;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 
10 namespace HZH_Controls.Controls
11 {
12     public partial class UCLEDDataTime : UserControl
13     {
14         private DateTime m_value;
15 
16         [Description(""), Category("自定义")]
17         public DateTime Value
18         {
19             get { return m_value; }
20             set
21             {
22                 m_value = value;
23                 string str = value.ToString("yyyy-MM-dd HH:mm:ss");
24                 for (int i = 0; i < str.Length; i++)
25                 {
26                     if (i == 10)
27                         continue;
28                     ((UCLEDNum)this.tableLayoutPanel1.Controls.Find("D" + (i + 1), false)[0]).Value = str[i];
29                 }
30             }
31         }
32 
33         private int m_lineWidth = 8;
34 
35         [Description("线宽度,为了更好的显示效果,请使用偶数"), Category("自定义")]
36         public int LineWidth
37         {
38             get { return m_lineWidth; }
39             set
40             {
41                 m_lineWidth = value;
42                 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
43                 {
44                     c.LineWidth = value;
45                 }
46             }
47         }
48 
49         [Description("颜色"), Category("自定义")]
50         public override System.Drawing.Color ForeColor
51         {
52             get
53             {
54                 return base.ForeColor;
55             }
56             set
57             {
58                 base.ForeColor = value;
59                 foreach (UCLEDNum c in this.tableLayoutPanel1.Controls)
60                 {
61                     c.ForeColor = value;
62                 }
63             }
64         }
65         public UCLEDDataTime()
66         {
67             InitializeComponent();
68             Value = DateTime.Now;
69         }
70     }
71 }

View Code

  1 namespace HZH_Controls.Controls
  2 {
  3     partial class UCLEDDataTime
  4     {
  5         /// <summary> 
  6         /// 必需的设计器变量。
  7         /// </summary>
  8         private System.ComponentModel.IContainer components = null;
  9 
 10         /// <summary> 
 11         /// 清理所有正在使用的资源。
 12         /// </summary>
 13         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
 14         protected override void Dispose(bool disposing)
 15         {
 16             if (disposing && (components != null))
 17             {
 18                 components.Dispose();
 19             }
 20             base.Dispose(disposing);
 21         }
 22 
 23         #region 组件设计器生成的代码
 24 
 25         /// <summary> 
 26         /// 设计器支持所需的方法 - 不要
 27         /// 使用代码编辑器修改此方法的内容。
 28         /// </summary>
 29         private void InitializeComponent()
 30         {
 31             this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
 32             this.D1 = new HZH_Controls.Controls.UCLEDNum();
 33             this.D2 = new HZH_Controls.Controls.UCLEDNum();
 34             this.D3 = new HZH_Controls.Controls.UCLEDNum();
 35             this.D4 = new HZH_Controls.Controls.UCLEDNum();
 36             this.D5 = new HZH_Controls.Controls.UCLEDNum();
 37             this.D6 = new HZH_Controls.Controls.UCLEDNum();
 38             this.D7 = new HZH_Controls.Controls.UCLEDNum();
 39             this.D8 = new HZH_Controls.Controls.UCLEDNum();
 40             this.D9 = new HZH_Controls.Controls.UCLEDNum();
 41             this.D10 = new HZH_Controls.Controls.UCLEDNum();
 42             this.D12 = new HZH_Controls.Controls.UCLEDNum();
 43             this.D13 = new HZH_Controls.Controls.UCLEDNum();
 44             this.D14 = new HZH_Controls.Controls.UCLEDNum();
 45             this.D15 = new HZH_Controls.Controls.UCLEDNum();
 46             this.D16 = new HZH_Controls.Controls.UCLEDNum();
 47             this.D17 = new HZH_Controls.Controls.UCLEDNum();
 48             this.D18 = new HZH_Controls.Controls.UCLEDNum();
 49             this.D19 = new HZH_Controls.Controls.UCLEDNum();
 50             this.tableLayoutPanel1.SuspendLayout();
 51             this.SuspendLayout();
 52             // 
 53             // tableLayoutPanel1
 54             // 
 55             this.tableLayoutPanel1.ColumnCount = 19;
 56             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 57             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 58             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 59             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 60             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 61             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 62             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 63             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 64             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 65             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 66             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 67             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 68             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 69             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 70             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 71             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 72             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 73             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 74             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 5.263158F));
 75             this.tableLayoutPanel1.Controls.Add(this.D1, 0, 0);
 76             this.tableLayoutPanel1.Controls.Add(this.D2, 1, 0);
 77             this.tableLayoutPanel1.Controls.Add(this.D3, 2, 0);
 78             this.tableLayoutPanel1.Controls.Add(this.D4, 3, 0);
 79             this.tableLayoutPanel1.Controls.Add(this.D5, 4, 0);
 80             this.tableLayoutPanel1.Controls.Add(this.D6, 5, 0);
 81             this.tableLayoutPanel1.Controls.Add(this.D7, 6, 0);
 82             this.tableLayoutPanel1.Controls.Add(this.D8, 7, 0);
 83             this.tableLayoutPanel1.Controls.Add(this.D9, 8, 0);
 84             this.tableLayoutPanel1.Controls.Add(this.D10, 9, 0);
 85             this.tableLayoutPanel1.Controls.Add(this.D12, 11, 0);
 86             this.tableLayoutPanel1.Controls.Add(this.D13, 12, 0);
 87             this.tableLayoutPanel1.Controls.Add(this.D14, 13, 0);
 88             this.tableLayoutPanel1.Controls.Add(this.D15, 14, 0);
 89             this.tableLayoutPanel1.Controls.Add(this.D16, 15, 0);
 90             this.tableLayoutPanel1.Controls.Add(this.D17, 16, 0);
 91             this.tableLayoutPanel1.Controls.Add(this.D18, 17, 0);
 92             this.tableLayoutPanel1.Controls.Add(this.D19, 18, 0);
 93             this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
 94             this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
 95             this.tableLayoutPanel1.Name = "tableLayoutPanel1";
 96             this.tableLayoutPanel1.RowCount = 1;
 97             this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
 98             this.tableLayoutPanel1.Size = new System.Drawing.Size(650, 58);
 99             this.tableLayoutPanel1.TabIndex = 1;
100             // 
101             // D1
102             // 
103             this.D1.Dock = System.Windows.Forms.DockStyle.Fill;
104             this.D1.LineWidth = 8;
105             this.D1.Location = new System.Drawing.Point(3, 3);
106             this.D1.Name = "D1";
107             this.D1.Size = new System.Drawing.Size(28, 52);
108             this.D1.TabIndex = 0;
109             this.D1.Value = '2';
110             // 
111             // D2
112             // 
113             this.D2.Dock = System.Windows.Forms.DockStyle.Fill;
114             this.D2.LineWidth = 8;
115             this.D2.Location = new System.Drawing.Point(37, 3);
116             this.D2.Name = "D2";
117             this.D2.Size = new System.Drawing.Size(28, 52);
118             this.D2.TabIndex = 1;
119             this.D2.Value = '0';
120             // 
121             // D3
122             // 
123             this.D3.Dock = System.Windows.Forms.DockStyle.Fill;
124             this.D3.LineWidth = 8;
125             this.D3.Location = new System.Drawing.Point(71, 3);
126             this.D3.Name = "D3";
127             this.D3.Size = new System.Drawing.Size(28, 52);
128             this.D3.TabIndex = 2;
129             this.D3.Value = '1';
130             // 
131             // D4
132             // 
133             this.D4.Dock = System.Windows.Forms.DockStyle.Fill;
134             this.D4.LineWidth = 8;
135             this.D4.Location = new System.Drawing.Point(105, 3);
136             this.D4.Name = "D4";
137             this.D4.Size = new System.Drawing.Size(28, 52);
138             this.D4.TabIndex = 3;
139             this.D4.Value = '9';
140             // 
141             // D5
142             // 
143             this.D5.Dock = System.Windows.Forms.DockStyle.Fill;
144             this.D5.LineWidth = 8;
145             this.D5.Location = new System.Drawing.Point(139, 3);
146             this.D5.Name = "D5";
147             this.D5.Size = new System.Drawing.Size(28, 52);
148             this.D5.TabIndex = 4;
149             this.D5.Value = '-';
150             // 
151             // D6
152             // 
153             this.D6.Dock = System.Windows.Forms.DockStyle.Fill;
154             this.D6.LineWidth = 8;
155             this.D6.Location = new System.Drawing.Point(173, 3);
156             this.D6.Name = "D6";
157             this.D6.Size = new System.Drawing.Size(28, 52);
158             this.D6.TabIndex = 5;
159             this.D6.Value = '0';
160             // 
161             // D7
162             // 
163             this.D7.Dock = System.Windows.Forms.DockStyle.Fill;
164             this.D7.LineWidth = 8;
165             this.D7.Location = new System.Drawing.Point(207, 3);
166             this.D7.Name = "D7";
167             this.D7.Size = new System.Drawing.Size(28, 52);
168             this.D7.TabIndex = 6;
169             this.D7.Value = '8';
170             // 
171             // D8
172             // 
173             this.D8.Dock = System.Windows.Forms.DockStyle.Fill;
174             this.D8.LineWidth = 8;
175             this.D8.Location = new System.Drawing.Point(241, 3);
176             this.D8.Name = "D8";
177             this.D8.Size = new System.Drawing.Size(28, 52);
178             this.D8.TabIndex = 7;
179             this.D8.Value = '-';
180             // 
181             // D9
182             // 
183             this.D9.Dock = System.Windows.Forms.DockStyle.Fill;
184             this.D9.LineWidth = 8;
185             this.D9.Location = new System.Drawing.Point(275, 3);
186             this.D9.Name = "D9";
187             this.D9.Size = new System.Drawing.Size(28, 52);
188             this.D9.TabIndex = 8;
189             this.D9.Value = '0';
190             // 
191             // D10
192             // 
193             this.D10.Dock = System.Windows.Forms.DockStyle.Fill;
194             this.D10.LineWidth = 8;
195             this.D10.Location = new System.Drawing.Point(309, 3);
196             this.D10.Name = "D10";
197             this.D10.Size = new System.Drawing.Size(28, 52);
198             this.D10.TabIndex = 9;
199             this.D10.Value = '1';
200             // 
201             // D12
202             // 
203             this.D12.Dock = System.Windows.Forms.DockStyle.Fill;
204             this.D12.LineWidth = 8;
205             this.D12.Location = new System.Drawing.Point(377, 3);
206             this.D12.Name = "D12";
207             this.D12.Size = new System.Drawing.Size(28, 52);
208             this.D12.TabIndex = 10;
209             this.D12.Value = '2';
210             // 
211             // D13
212             // 
213             this.D13.Dock = System.Windows.Forms.DockStyle.Fill;
214             this.D13.LineWidth = 8;
215             this.D13.Location = new System.Drawing.Point(411, 3);
216             this.D13.Name = "D13";
217             this.D13.Size = new System.Drawing.Size(28, 52);
218             this.D13.TabIndex = 11;
219             this.D13.Value = '3';
220             // 
221             // D14
222             // 
223             this.D14.Dock = System.Windows.Forms.DockStyle.Fill;
224             this.D14.LineWidth = 8;
225             this.D14.Location = new System.Drawing.Point(445, 3);
226             this.D14.Name = "D14";
227             this.D14.Size = new System.Drawing.Size(28, 52);
228             this.D14.TabIndex = 12;
229             this.D14.Value = ':';
230             // 
231             // D15
232             // 
233             this.D15.Dock = System.Windows.Forms.DockStyle.Fill;
234             this.D15.LineWidth = 8;
235             this.D15.Location = new System.Drawing.Point(479, 3);
236             this.D15.Name = "D15";
237             this.D15.Size = new System.Drawing.Size(28, 52);
238             this.D15.TabIndex = 13;
239             this.D15.Value = '0';
240             // 
241             // D16
242             // 
243             this.D16.Dock = System.Windows.Forms.DockStyle.Fill;
244             this.D16.LineWidth = 8;
245             this.D16.Location = new System.Drawing.Point(513, 3);
246             this.D16.Name = "D16";
247             this.D16.Size = new System.Drawing.Size(28, 52);
248             this.D16.TabIndex = 14;
249             this.D16.Value = '1';
250             // 
251             // D17
252             // 
253             this.D17.Dock = System.Windows.Forms.DockStyle.Fill;
254             this.D17.LineWidth = 8;
255             this.D17.Location = new System.Drawing.Point(547, 3);
256             this.D17.Name = "D17";
257             this.D17.Size = new System.Drawing.Size(28, 52);
258             this.D17.TabIndex = 15;
259             this.D17.Value = ':';
260             // 
261             // D18
262             // 
263             this.D18.Dock = System.Windows.Forms.DockStyle.Fill;
264             this.D18.LineWidth = 8;
265             this.D18.Location = new System.Drawing.Point(581, 3);
266             this.D18.Name = "D18";
267             this.D18.Size = new System.Drawing.Size(28, 52);
268             this.D18.TabIndex = 16;
269             this.D18.Value = '5';
270             // 
271             // D19
272             // 
273             this.D19.Dock = System.Windows.Forms.DockStyle.Fill;
274             this.D19.LineWidth = 8;
275             this.D19.Location = new System.Drawing.Point(615, 3);
276             this.D19.Name = "D19";
277             this.D19.Size = new System.Drawing.Size(32, 52);
278             this.D19.TabIndex = 17;
279             this.D19.Value = '3';
280             // 
281             // UCLEDDataTime
282             // 
283             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
284             this.Controls.Add(this.tableLayoutPanel1);
285             this.Name = "UCLEDDataTime";
286             this.Size = new System.Drawing.Size(650, 58);
287             this.tableLayoutPanel1.ResumeLayout(false);
288             this.ResumeLayout(false);
289 
290         }
291 
292         #endregion
293 
294         private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
295         private UCLEDNum D1;
296         private UCLEDNum D2;
297         private UCLEDNum D3;
298         private UCLEDNum D4;
299         private UCLEDNum D5;
300         private UCLEDNum D6;
301         private UCLEDNum D7;
302         private UCLEDNum D8;
303         private UCLEDNum D9;
304         private UCLEDNum D10;
305         private UCLEDNum D12;
306         private UCLEDNum D13;
307         private UCLEDNum D14;
308         private UCLEDNum D15;
309         private UCLEDNum D16;
310         private UCLEDNum D17;
311         private UCLEDNum D18;
312         private UCLEDNum D19;
313     }
314 }

View Code

 

如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧

版权声明:本文为bfyx原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/bfyx/p/11447261.html