此篇来自网络,在此感谢原作者
问题:如何让TextBox显示只有下边的一条线?like this :
解决方案:自定义TextBox控件
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Test
{
public class MyTextBox: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);
}
}
}
}
}
}
使用帮助:
1.把自定义的控件放在你要放的地方。ok
2.修改其属性:BorderStyle :None
UnderLine:true
3.同喜你。自定义控件成功!!!