textbox的边框如何改变颜色?,重写也可以!

解决方案 »

  1.   

    一定要重写了,继承一个控件,这样应该就可以了,颜色可以自己定义,我这里使用的红色。
    public class MyTextBox: TextBox
    {
    ....
    protected override void WndProc(ref Message m)
    {
      base.WndProc(ref m);
      if (m.Msg == WM_PAINT)
      {
        Graphics g = this.CreateGraphics();
        g.DrawRectangle(Pens.Red, 0, 0, this.Width - 1, this.Height - 1);
        g.Dispose();
      }
    }
    .....
    }
      

  2.   

    .txtBox
    {
    font-size: 8pt;
    font-family: Verdana;
    width: 100%;
    height: 19px;
    border: 1px solid #7b9ebd;
    vertical-align: middle; 
    }
      

  3.   

    Graphics g = this.CreateGraphics();
    g.DrawRectangle(Pens.Red, 0, 0, this.Width - 1, this.Height - 1);
      

  4.   

    TextBox1 .BorderColor = System.Drawing .Color .Red
      

  5.   

    TextBox1.BorderColor = System.Drawing.Color.Blue
      

  6.   

    一楼和二楼的分别是WinForm和WebForm中的实现方法!
      

  7.   

    不用重载;
    this.TextBox1 .BorderStyle = BorderStyle .Solid ;
    this.TextBox1 .BorderColor = System.Drawing .Color .Red  ;