本帖最后由 shencb 于 2009-09-21 19:52:29 编辑

解决方案 »

  1.   


    .inputT { 
    BORDER-RIGHT: #412e2f 0px solid; 
    BORDER-TOP: #412e2f 0px solid; 
    BACKGROUND: #fff; 
    BORDER-LEFT: #412e2f 0px solid; 
    BORDER-BOTTOM: #412e2f 1px solid;
    width:120px;
    }
    这是我样式表里面的,你自己改改
      

  2.   

    Look:using System;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Runtime.InteropServices;public class MyTextBox : System.Windows.Forms.TextBox
    {
        #region 常量    const int WM_NCPAINT = 0x85;
        const int WM_PAINT = 0xf;
        const int MY_NCPAINT = 0xff;    #endregion    #region WindowsAPI    [DllImport("User32")]
        static extern int SendMessage(
            IntPtr hWnd, 
            uint Msg, 
            uint wParam, 
            uint lParam 
            );
        [DllImport("user32.dll")]
        static extern IntPtr GetWindowDC(IntPtr hWnd);
        [DllImport("user32.dll")]
        public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);    #endregion    #region 变量    Color _BorderColor = Color.Black;
        Color _FocusedColor = Color.FromArgb(100, 100, 230);
        bool _FocusIn = false;    #endregion    #region 重载方法
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if ((m.Msg == WM_NCPAINT || m.Msg == WM_PAINT))
            {
                PaintBorder(m);
                m.Result = IntPtr.Zero;
            }
        }    protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            _FocusIn = true;
            SendMessage(this.Handle, WM_NCPAINT, 0, MY_NCPAINT);
        }    protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            _FocusIn = false;
            SendMessage(Handle, WM_NCPAINT, 0, MY_NCPAINT);
        }
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            SendMessage(this.Handle, WM_NCPAINT, 0, MY_NCPAINT);
        }
        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);
            SendMessage(this.Handle, WM_NCPAINT, 0, MY_NCPAINT);
        }    #endregion    #region 画边框
        private void PaintBorder(Message m)
        {
            IntPtr hdc = GetWindowDC(m.HWnd);
            if (hdc.ToInt32() == 0)
                return;
            Graphics g = Graphics.FromHdc(hdc);        Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
            Point point = rect.Location;
            point.Offset(2, 2);
            Size size = rect.Size;
            size.Width -= 4;
            size.Height -= 4;        Rectangle rclient = new Rectangle(point, size);        Pen p = null;
            Region region = new Region(rect);
            region.Exclude(rclient);
            if ((_FocusIn || Focused) && m.LParam.ToInt32() == MY_NCPAINT)
            {
                p = new Pen(new SolidBrush(_FocusedColor), 2);
                g.SetClip(region, System.Drawing.Drawing2D.CombineMode.Intersect);
                g.FillRegion(new SolidBrush(this.BackColor), region);
                g.DrawRectangle(p, new Rectangle(new Point(0, 0), new Size(rect.Width, rect.Height)));
            }
            else
            {
                p = new Pen(new SolidBrush(_BorderColor), 1);
                if (m.LParam.ToInt32() == MY_NCPAINT)
                    g.SetClip(region, System.Drawing.Drawing2D.CombineMode.Intersect);
                g.FillRegion(new SolidBrush(this.BackColor), region);
                g.DrawLine(p, new Point(rect.Left, rect.Bottom - 1), new Point(rect.Right, rect.Bottom - 1));
            }
            ReleaseDC(m.HWnd, hdc);
        }
        #endregion
    }