帶底線的LABEL控制項

來源:互聯網
上載者:User

帶底線的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         }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.