C#做了一个无边框只有一根横线的TEXTBOX, 求大婶帮忙
本帖最后由 icelovey 于 2013-10-26 19:51:08 编辑 做了一个无边框只有一根横线的TextBox, 因为考虑到窗口变化大小, 或者只读状态变更等问题,
里面有个重绘画线的线程,代码类似这样的
Graphics g = this.CreateGraphics();
g.Clear(Color.SeaShell);
Brush b = new SolidBrush(Color.Blue);
Pen p = new Pen(b,11);
p.Width = 12;
g.DrawLine(p, 100, 300, 100, 400);
public partial class CustomControl1 : TextBox
{
public CustomControl1()
{
InitializeComponent();
this.BorderStyle = BorderStyle.None;
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.Olive, 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));
}
}
}
}