C#只有底边框的Textbox

自定义控件实现,效果如下

代码如下

代码
public partial class LineTextBox : TextBox
{
public LineTextBox()
{
this.Width
= 100;
this.BorderStyle
= BorderStyle.None;
}
private Color _linecolor
= Color.Black;
/// <summary>
/// 线条颜色
/// </summary>
public Color LineColor
{
get
{
return this._linecolor;
}
set
{
this._linecolor
= value;
this.Invalidate();
}
}
private const
int WM_PAINT = 0xF;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_PAINT)
{
DrawLine();
}
}
//只画底边
private void DrawLine()
{
Graphics g
= this.CreateGraphics();
using (Pen p
= new Pen(this._linecolor))
{
g.DrawLine(p,
0, this.Height - 1, this.Width, this.Height - 1);
}
}
}

原文地址:https://www.cnblogs.com/cnbwang/p/1909818.html