winform中如何重画TextBox为条线:
我 这样处理了没有效果: protected override void OnPaint(PaintEventArgs pe)
{
// TODO: 在此添加自定义绘画代码 // 调用基类 OnPaint

Point start=new Point(0,0);
Point end=new Point(this.Size.Width,this.Size.Height);
    SolidBrush newbrush=new SolidBrush(Color.Red); Pen newpen=new Pen(newbrush,3);
pe.Graphics.DrawLine(newpen,start,end);
base.OnPaint(pe);

}
请问高手怎样弄,提供代码 谢谢

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Windows.Forms;namespace Rascal.Controls.Windows.Forms
    {
    /// <summary>
    /// 自定义TextBox类,创建一个自己定义样式的TextBox。
    /// </summary>
    public class TextBox:System.Windows.Forms.TextBox
    {
    public TextBox():base()
    {
    } protected override void WndProc(ref Message m)
    {
    base.WndProc(ref m);

    const int WM_PAINT = 0x000F; //this.BorderStyle = BorderStyle.FixedSingle; if (m.Msg == WM_PAINT )
    {
    Graphics g = Graphics.FromHwnd(this.Handle);

    g.DrawRectangle(Pens.DarkBlue, this.ClientRectangle.Left,
    this.ClientRectangle.Top, this.ClientRectangle.Width - 1,
    this.ClientRectangle.Height - 1);

    //g.DrawLine(Pens.Red, new Point(this.ClientRectangle.Left, this.ClientRectangle.Height-1), new Point(this.ClientRectangle.Width, this.ClientRectangle.Height-1));
    g.Dispose();
    }

    }
    }
    }