我前几天有做,也碰到点问题,一起探讨下:
边框我有了
但是我的问题是背景图,每次输入文字就会重绘,以致看不到输入的文字(实际.text已经得到)
是不是还要override onTextChange?我的代码如下:public class TextBoxBlue:TextBox
{
  protected  override void WndProc(ref Message m)
{
   base.WndProc(ref m);
   int WM_PAINT=15;
   if (m.Msg==WM_PAINT)//好象这个判断不用也可以
   {
    Graphics g = Graphics.FromHwnd(this.Handle);
    g.DrawRectangle(Pens.Blue,this.ClientRectangle.Left,this.ClientRectangle.Top,this.ClientRectangle.Width - 1,this.ClientRectangle.Height - 1);//画边框
    g.DrawImage((Bitmap)Bitmap.FromFile(@"c:\00.bmp"),this.ClientRectangle.Left,this.ClientRectangle.Top,this.ClientRectangle.Width - 1,this.ClientRectangle.Height - 1);//画背景图
    g.Dispose();
    }
  }

解决方案 »

  1.   

    TO:atian25(阿天)
    你不觉得边框还是没有改变吗,只是在编辑区的外围加了一个兰色框
    你的文字也要重绘啊,用g.DrawString  不过我试了好象又把背景图覆盖了
      

  2.   

    TextBox的Border不属于客户区,应当在WM_NCPAINT消息里绘制.
    而且this.ClientRectangle得到的是客户区的大小,要使用this.Size.
      

  3.   

    同意楼上。
    在WndProc中处理WM_NCPAINT消息即可。
    如果有尺寸的变化,还需要处理WM_NCCALCSIZE消息。
    protected override void         WndProc(ref Message m)
    {
    switch( m.Msg )
    {
    case Platform.NativeMethods.WM_NCPAINT:
    Graphics g = Graphics.FromHdc(...GetWindowDC(m.HWnd));//API
             g.Draw...(...);
    base.WndProc(ref m);
                                        ...
                                }
    }
      

  4.   

    ControlPaint.DrawBorder ,行不行?
      

  5.   

    protected override void WndProc(ref Message m)
    {
        int msg = m.Msg;
        base.WndProc (ref m);
        switch( msg )  
        {
            case WM_NCPAINT:
            {
                Graphics borderG = this.Parent.CreateGraphics();
       borderG.DrawRectangle( new Pen(this.BackColor), this.Left+1, this.Top+1, this.Width-2, this.Height-2 );
       break;
    }
         }
    }
      

  6.   

    我主要是想把TextBox的上边框和左边框的 深灰色条用编辑区的颜色覆盖就成了一个Flat的TextBox了
      

  7.   

    呵呵~~自己写一个控件多好,完全自画,一个TextBox的功能又不复杂`~
      

  8.   

    ControlPaint.DrawBorder
    ControlPaint.DrawBorder
    ControlPaint.DrawBorder
    ControlPaint.DrawBorder
    ControlPaint.DrawBorder
    ControlPaint.DrawBorder
    ControlPaint.DrawBorder
      

  9.   

    如果你要画上边框和左边框,你的代码是不是算错了?
    似乎应该是:borderG.DrawRectangle( new Pen(this.BackColor), this.Left-1, this.Top-1, this.Width-2, this.Height-2 );
      

  10.   

    to cherno(且歌且狂):既然很简单,能麻烦把它帖出来吗?
      

  11.   

    TO  sarmoo(Echo):
      我都试过了,就是没用,现在关键是Graphic对象,我试了一下:
      用this.CreateGraphics(); 只能在TextBox的编辑区内绘图。
      用this.Parent.CreateGraphics(); 就只能在它的Parent上绘图。
      始终不能影响边框。
    我尝试过上面两个Graphic填充一个区域,但最后边框还是没有改变
      

  12.   

    注意我给你的例子:
    Graphics g = Graphics.FromHdc(...GetWindowDC(m.HWnd));//API
    需调用GetWindowDC(API函数)得到windowDC
      

  13.   

    我对 sarmoo(Echo) 例子中的“Platform.NativeMethods.WM_NCPAINT:”比较关注,不知道,如何调用????
      

  14.   

    对不起,那个实际上就是WM_NCPAINT,只是个人写法而已。
      

  15.   

    谢谢  sarmoo(Echo)  
    以搞定:
    switch( msg )  
    {
        case WM_NCPAINT:
        {   
    Pen pen = new Pen(this.BackColor);
    Graphics borderG = Graphics.FromHdc( GetWindowDC(m.HWnd) ); borderG.DrawRectangle( pen, 1, 1, this.Size.Width-2, this.Size.Height-             2 ); borderG.Dispose();
    pen.Dispose();
    break;
        }
    }
      

  16.   

    顺便问一下,
    .net Framework中要强制发一个WM_NCPAINT消息,该用什么方法
      

  17.   

    codeproject上例子很多啊,去找找