日期:2014-05-18  浏览次数:21073 次

C#让TextBox只显示一条横线
如使用C#让TextBox只显示一条横线??
也就是说把TextBox上、左、右的边框去掉.
怎么做啊,高手指点一下。
给个想路也行啊!

------解决方案--------------------
自已重写TextBox,可以参考下面的代码:
public class UnderLineBox : TextBox
{
private bool m_underLine;

public bool UnderLine
{
get { return m_underLine; }
set
{
if (this.m_underLine != value)
{
if (value)
{
this.BorderStyle = BorderStyle.None;
}
m_underLine = value;
}
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0xf || m.Msg == 0x14 || m.Msg == 0x85)
{
if (this.BorderStyle == BorderStyle.None)
{
if (m_underLine)
{
using (Graphics g = Graphics.FromHwnd(this.Handle))
{
g.DrawLine(SystemPens.ControlText, 0, this.Height - 1, this.Width - 1, this.Height - 1);
}
}
}
}
}
}