• 数字时间控件----------WinForm控件开发系列


     该控件继承 Control 基类开发的。

    数字时间的格式有 时、时分、时分秒、时分秒毫秒 4种。各个部分可以设置成独立的颜色。

    事件由数字符号组成,以下是数字原理,数字可分为7笔,如下

     1         private void draw_vertical_11(Graphics g, Pen pen, RectangleF bounds_rect)
     2         {
     3             float x1 = bounds_rect.X + this.cap_c;
     4             float y1 = bounds_rect.Y + this.LineWidth + 1;
     5             float x2 = bounds_rect.X + this.cap_c;
     6             float y2 = bounds_rect.Y + this.line_h + 1;
     7             g.DrawLine(pen, x1, y1, x2, y2);
     8         }
     9         private void draw_vertical_21(Graphics g, Pen pen, RectangleF bounds_rect)
    10         {
    11             float x1 = bounds_rect.X + this.cap_c;
    12             float y1 = bounds_rect.Y + this.LineWidth + this.line_h + 3;
    13             float x2 = bounds_rect.X + this.cap_c;
    14             float y2 = bounds_rect.Y + this.line_h + this.line_h + 3;
    15             g.DrawLine(pen, x1, y1, x2, y2);
    16         }
    17 
    18         private void draw_horizontal_1(Graphics g, Pen pen, RectangleF bounds_rect)
    19         {
    20             float x1 = 1 + bounds_rect.X + this.LineWidth;
    21             float y1 = bounds_rect.Y + this.cap_c;
    22             float x2 = 1 + bounds_rect.X + this.line_w;
    23             float y2 = bounds_rect.Y + this.cap_c;
    24             g.DrawLine(pen, x1, y1, x2, y2);
    25         }
    26         private void draw_horizontal_2(Graphics g, Pen pen, RectangleF bounds_rect)
    27         {
    28             float x1 = 1 + bounds_rect.X + this.LineWidth;
    29             float y1 = 2 + bounds_rect.Y + this.cap_c + this.line_h;
    30             float x2 = 1 + bounds_rect.X + this.line_w;
    31             float y2 = 2 + bounds_rect.Y + this.cap_c + this.line_h;
    32             g.DrawLine(pen, x1, y1, x2, y2);
    33         }
    34         private void draw_horizontal_3(Graphics g, Pen pen, RectangleF bounds_rect)
    35         {
    36             float x1 = 1 + bounds_rect.X + this.LineWidth;
    37             float y1 = 4 + bounds_rect.Y + this.cap_c + this.line_h + this.line_h;
    38             float x2 = 1 + bounds_rect.X + this.line_w;
    39             float y2 = 4 + bounds_rect.Y + this.cap_c + this.line_h + this.line_h;
    40             g.DrawLine(pen, x1, y1, x2, y2);
    41         }
    42 
    43         private void draw_vertical_12(Graphics g, Pen pen, RectangleF bounds_rect)
    44         {
    45             float x1 = bounds_rect.X + this.cap_c + 2 + this.line_w;
    46             float y1 = bounds_rect.Y + this.LineWidth + 1;
    47             float x2 = bounds_rect.X + this.cap_c + 2 + this.line_w;
    48             float y2 = bounds_rect.Y + this.line_h + 1;
    49             g.DrawLine(pen, x1, y1, x2, y2);
    50         }
    51         private void draw_vertical_22(Graphics g, Pen pen, RectangleF bounds_rect)
    52         {
    53             float x1 = bounds_rect.X + this.cap_c + 2 + this.line_w;
    54             float y1 = bounds_rect.Y + this.LineWidth + this.line_h + +3;
    55             float x2 = bounds_rect.X + this.cap_c + 2 + this.line_w;
    56             float y2 = bounds_rect.Y + this.line_h + this.line_h + 3;
    57             g.DrawLine(pen, x1, y1, x2, y2);
    58         }
    笔画组成数字源码
      1         private void draw_0(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
      2         {
      3             this.draw_vertical_11(g, highlight_pen, bounds_rect);
      4             this.draw_vertical_21(g, highlight_pen, bounds_rect);
      5 
      6             this.draw_horizontal_1(g, highlight_pen, bounds_rect);
      7             if (this.ShadowShow)
      8                 this.draw_horizontal_2(g, shadow_pen, bounds_rect);
      9             this.draw_horizontal_3(g, highlight_pen, bounds_rect);
     10 
     11             this.draw_vertical_12(g, highlight_pen, bounds_rect);
     12             this.draw_vertical_22(g, highlight_pen, bounds_rect);
     13         }
     14         private void draw_1(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
     15         {
     16             if (this.ShadowShow)
     17                 this.draw_vertical_11(g, shadow_pen, bounds_rect);
     18             if (this.ShadowShow)
     19                 this.draw_vertical_21(g, shadow_pen, bounds_rect);
     20 
     21             if (this.ShadowShow)
     22                 this.draw_horizontal_1(g, shadow_pen, bounds_rect);
     23             if (this.ShadowShow)
     24                 this.draw_horizontal_2(g, shadow_pen, bounds_rect);
     25             if (this.ShadowShow)
     26                 this.draw_horizontal_3(g, shadow_pen, bounds_rect);
     27 
     28             this.draw_vertical_12(g, highlight_pen, bounds_rect);
     29             this.draw_vertical_22(g, highlight_pen, bounds_rect);
     30         }
     31         private void draw_2(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
     32         {
     33             if (this.ShadowShow)
     34                 this.draw_vertical_11(g, shadow_pen, bounds_rect);
     35             this.draw_vertical_21(g, highlight_pen, bounds_rect);
     36 
     37             this.draw_horizontal_1(g, highlight_pen, bounds_rect);
     38             this.draw_horizontal_2(g, highlight_pen, bounds_rect);
     39             this.draw_horizontal_3(g, highlight_pen, bounds_rect);
     40 
     41             this.draw_vertical_12(g, highlight_pen, bounds_rect);
     42             if (this.ShadowShow)
     43                 this.draw_vertical_22(g, shadow_pen, bounds_rect);
     44         }
     45         private void draw_3(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
     46         {
     47             if (this.ShadowShow)
     48                 this.draw_vertical_11(g, shadow_pen, bounds_rect);
     49             if (this.ShadowShow)
     50                 this.draw_vertical_21(g, shadow_pen, bounds_rect);
     51 
     52             this.draw_horizontal_1(g, highlight_pen, bounds_rect);
     53             this.draw_horizontal_2(g, highlight_pen, bounds_rect);
     54             this.draw_horizontal_3(g, highlight_pen, bounds_rect);
     55 
     56             this.draw_vertical_12(g, highlight_pen, bounds_rect);
     57             this.draw_vertical_22(g, highlight_pen, bounds_rect);
     58         }
     59         private void draw_4(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
     60         {
     61             this.draw_vertical_11(g, highlight_pen, bounds_rect);
     62             if (this.ShadowShow)
     63                 this.draw_vertical_21(g, shadow_pen, bounds_rect);
     64 
     65             if (this.ShadowShow)
     66                 this.draw_horizontal_1(g, shadow_pen, bounds_rect);
     67             this.draw_horizontal_2(g, highlight_pen, bounds_rect);
     68             if (this.ShadowShow)
     69                 this.draw_horizontal_3(g, shadow_pen, bounds_rect);
     70 
     71             this.draw_vertical_12(g, highlight_pen, bounds_rect);
     72             this.draw_vertical_22(g, highlight_pen, bounds_rect);
     73         }
     74         private void draw_5(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
     75         {
     76             this.draw_vertical_11(g, highlight_pen, bounds_rect);
     77             if (this.ShadowShow)
     78                 this.draw_vertical_21(g, shadow_pen, bounds_rect);
     79 
     80             this.draw_horizontal_1(g, highlight_pen, bounds_rect);
     81             this.draw_horizontal_2(g, highlight_pen, bounds_rect);
     82             this.draw_horizontal_3(g, highlight_pen, bounds_rect);
     83 
     84             if (this.ShadowShow)
     85                 this.draw_vertical_12(g, shadow_pen, bounds_rect);
     86             this.draw_vertical_22(g, highlight_pen, bounds_rect);
     87         }
     88         private void draw_6(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
     89         {
     90             this.draw_vertical_11(g, highlight_pen, bounds_rect);
     91             this.draw_vertical_21(g, highlight_pen, bounds_rect);
     92 
     93             this.draw_horizontal_1(g, highlight_pen, bounds_rect);
     94             this.draw_horizontal_2(g, highlight_pen, bounds_rect);
     95             this.draw_horizontal_3(g, highlight_pen, bounds_rect);
     96 
     97             if (this.ShadowShow)
     98                 this.draw_vertical_12(g, shadow_pen, bounds_rect);
     99             this.draw_vertical_22(g, highlight_pen, bounds_rect);
    100         }
    101         private void draw_7(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
    102         {
    103             if (this.ShadowShow)
    104                 this.draw_vertical_11(g, shadow_pen, bounds_rect);
    105             if (this.ShadowShow)
    106                 this.draw_vertical_21(g, shadow_pen, bounds_rect);
    107 
    108             this.draw_horizontal_1(g, highlight_pen, bounds_rect);
    109             if (this.ShadowShow)
    110                 this.draw_horizontal_2(g, shadow_pen, bounds_rect);
    111             if (this.ShadowShow)
    112                 this.draw_horizontal_3(g, shadow_pen, bounds_rect);
    113 
    114             this.draw_vertical_12(g, highlight_pen, bounds_rect);
    115             this.draw_vertical_22(g, highlight_pen, bounds_rect);
    116         }
    117         private void draw_8(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
    118         {
    119             this.draw_vertical_11(g, highlight_pen, bounds_rect);
    120             this.draw_vertical_21(g, highlight_pen, bounds_rect);
    121 
    122             this.draw_horizontal_1(g, highlight_pen, bounds_rect);
    123             this.draw_horizontal_2(g, highlight_pen, bounds_rect);
    124             this.draw_horizontal_3(g, highlight_pen, bounds_rect);
    125 
    126             this.draw_vertical_12(g, highlight_pen, bounds_rect);
    127             this.draw_vertical_22(g, highlight_pen, bounds_rect);
    128         }
    129         private void draw_9(Graphics g, Pen highlight_pen, RectangleF bounds_rect, Pen shadow_pen)
    130         {
    131             this.draw_vertical_11(g, highlight_pen, bounds_rect);
    132             if (this.ShadowShow)
    133                 this.draw_vertical_21(g, shadow_pen, bounds_rect);
    134 
    135             this.draw_horizontal_1(g, highlight_pen, bounds_rect);
    136             this.draw_horizontal_2(g, highlight_pen, bounds_rect);
    137             this.draw_horizontal_3(g, highlight_pen, bounds_rect);
    138 
    139             this.draw_vertical_12(g, highlight_pen, bounds_rect);
    140             this.draw_vertical_22(g, highlight_pen, bounds_rect);
    141         }
    142         private void draw_split(Graphics g, SolidBrush highlight_sb, RectangleF bounds_rect)
    143         {
    144             RectangleF top_rect = new RectangleF(bounds_rect.X + (bounds_rect.Width - this.LineWidth) / 2, bounds_rect.Y + (bounds_rect.Height / 2 - this.LineWidth) / 2, this.LineWidth, this.LineWidth);
    145             RectangleF bottom_rect = new RectangleF(bounds_rect.X + (bounds_rect.Width - this.LineWidth) / 2, bounds_rect.Y + bounds_rect.Height / 2 + (bounds_rect.Height / 2 - this.LineWidth) / 2, this.LineWidth, this.LineWidth);
    146             g.FillEllipse(highlight_sb, top_rect);
    147             g.FillEllipse(highlight_sb, bottom_rect);
    148         }
    0-9数字结构源码

    新增类如下

    新增属性如下

    控件库的源码已整体发布到gitee,下载地址:(花木兰控件库)https://gitee.com/tlmbem/hml

  • 相关阅读:
    【NOIP2016】换教室
    【NOIP模拟赛】总结
    【Codeforces Round 418】An impassioned circulation of affection DP
    DP测试总结
    【NOIP2012】疫情控制
    【HNOI2016】序列 莫队+单调栈+RMQ
    【Luogu P2709 小B的询问】莫队
    【HNOI2017】影魔
    【HNOI2017】大佬
    阿里云MaxCompute 2019-7月刊
  • 原文地址:https://www.cnblogs.com/tlmbem/p/11299008.html
Copyright © 2020-2023  润新知