只有底边的TextBox

1 using System.Windows.Forms;
2 using System.Drawing;
3
4 namespace WindowsFormsApplication1
5 {
6 public partial class LineTextBox : TextBox
7 {
8 public LineTextBox()
9 {
10 this.Multiline = false;
11 this.Width = 100;
12 this.Height = 20;
13 this.BorderStyle = BorderStyle.None;
14 }
15 private Color _linecolor = Color.Black;
16 /// <summary>
17 /// 线条颜色
18 /// </summary>
19 public Color LineColor
20 {
21 get
22 {
23 return this._linecolor;
24 }
25 set
26 {
27 this._linecolor = value;
28 this.Invalidate();
29 }
30 }
31 private const int WM_PAINT = 0xF;
32 protected override void WndProc(ref Message m)
33 {
34 base.WndProc(ref m);
35 if (m.Msg == WM_PAINT)
36 {
37 DrawLine();
38 }
39 }
40 //只画底边
41 private void DrawLine()
42 {
43 Graphics g = this.CreateGraphics();
44 using (Pen p = new Pen(this._linecolor))
45 {
46 g.DrawLine(p, 0, this.Height -1, this.Width, this.Height -1);
47 }
48 }
49 }
50 }
posted @ 2011-03-28 00:28  diaboo  阅读(171)  评论(0)    收藏  举报