本帖最后由 qlf2008 于 2010-05-21 15:08:52 编辑

解决方案 »

  1.   

    2,3问题已经解决
    楼主的想法在思路上是没有问题的,问题的出现是因为TextBox的本身.因为它在处理显示的时候除Paint外还有两个消息TextBox也在画,而这两个消息默认是没有事件处理的,也就是说这是TextBox内部的问题,要解决这个问题就好说了,来提前处理这些消息就行了,怎么做呢?   
      这个好说,按如下的代码写就行了:   
      public   class   MyTextBox   :   TextBox   
      {   
        
      public   MyTextBox()   
      {   
      this.BorderStyle   =   BorderStyle.FixedSingle;   
      }   
      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.FixedSingle)   
      {   
      using   (Graphics   g   =   Graphics.FromHwnd(this.Handle))   
      {   
      using   (Pen   pen   =   new   Pen(Color.Red))   
      {   
      g.DrawRectangle(pen,   0,   0,   this.Width   -   1,   this.Height   -   1);   
      }   
      }   
      }   
      }   
      }   
      }