• 带下划线的LABEL控件


    带下划线的LABEL控件

    继承自Label,代码如下:

      1 using System.Drawing.Drawing2D;
      2 using System.Windows.Forms;
      3 using System.Collections.Generic;
      4 using System.ComponentModel;
      5 using System.Linq;
      6 using System.Text;
      7 
      8 namespace CustomControlSample
      9 {
     10     public class LineLabel:System.Windows.Forms.Label
     11     {
     12         private Color _lineColor;
     13         private float _lineThick;
     14         private float[] _DashPattern;
     15         private DashStyle _DashStyle;
     16 
     17         public LineLabel()
     18         {
     19             _lineColor = base.ForeColor;
     20             _lineThick = 1f;
     21             _DashStyle = DashStyle.Solid;
     22         }
     23 
     24         [Browsable(true)]
     25         public Color LineColor
     26         {
     27             get
     28             {
     29                 return _lineColor;
     30             }
     31             set
     32             {
     33                 _lineColor = value;
     34                 Invalidate();
     35             }
     36         }
     37 
     38         [Browsable(true)]
     39         public float LineThick
     40         {
     41             get
     42             {
     43                 return _lineThick;
     44             }
     45             set
     46             {
     47                 _lineThick = value;
     48                 Invalidate();
     49             }
     50         }
     51 
     52         [Browsable(true)]
     53         public float LinePenMode
     54         {
     55             get
     56             {
     57                 return _lineThick;
     58             }
     59             set
     60             {
     61                 _lineThick = value;
     62                 Invalidate();
     63             }
     64         }
     65 
     66         [Browsable(true)]
     67         public float[] LineDashPattern
     68         {
     69             get
     70             {
     71                 return _DashPattern;
     72             }
     73             set
     74             {
     75                 _DashPattern = value;
     76                 Invalidate();
     77             }
     78         }
     79 
     80         [Browsable(true)]
     81         public DashStyle LineDashStyle
     82         {
     83             get
     84             {
     85                 return _DashStyle;
     86             }
     87             set
     88             {
     89                 _DashStyle = value;
     90                 Invalidate();
     91             }
     92         }
     93 
     94         protected override void OnPaint(PaintEventArgs e)
     95         {
     96             base.OnPaint(e);
     97             //StringFormat style = new StringFormat();
     98             //e.Graphics.DrawString(
     99             //    base.Text,
    100             //    Font,
    101             //    new SolidBrush(base.ForeColor),
    102             //    ClientRectangle, style);
    103 
    104             Pen p = new Pen(LineColor, LineThick);
    105             p.DashStyle = LineDashStyle;
    106             if ((p.DashStyle == DashStyle.DashDot) || (p.DashStyle == DashStyle.DashDotDot))
    107                 p.DashPattern = LineDashPattern;
    108             e.Graphics.DrawLine(p,2,this.Height-1, this.Width,this.Height-1);
    109         }
  • 相关阅读:
    minikube国内在线部署体验
    分表与分库使用场景以及设计方式
    epool与select有什么区别
    使用ssh-keygen生成私钥和公钥
    mysql关键字冲突
    MySQL 获取当前时间戳
    平时常说的ThreadLocal,今天就彻底解决它
    mysql和mssql最大连接数
    Spring Boot实战:拦截器与过滤器
    Mysql 索引问题-日期索引使用
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2839656.html
Copyright © 2020-2023  润新知