自定义控件-TextBoxEx,让其无边框只有下划线

自定义控件,继承TextBox 

代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Do
{
class TextBoxEx : TextBox
{
public TextBoxEx()
{
this.BorderStyle = BorderStyle.None;
// BackColor也可以自己设置
this.BackColor = SystemColors.Control;
}
private int WM_PAINT = 0x000F;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

if (m.Msg == WM_PAINT)
{
Pen pen
= new Pen(Brushes.Black, 1.5f);
using (Graphics g = this.CreateGraphics())
{
g.DrawLine(pen,
new Point(0, this.Size.Height - 1), new Point(this.Size.Width, this.Size.Height - 1));
}
}
}
}
}

 

 

 

posted on 2010-07-23 14:08  raychn  阅读(824)  评论(2编辑  收藏  举报