下面的AutoFillForm可以不继承,只是我用来自动填充窗体控件的一个接口
public partial class TxtLine : TextBox,AutoFillFrom
{
public TxtLine()
{
InitializeComponent();
this.Multiline = true;
this.Width = 100;
this.Height = 16;
this.BorderStyle = BorderStyle.None;
}
public string DataField
{ get; set; }
public string Description
{ get; set; }
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);
}
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}