zoukankan      html  css  js  c++  java
  • 加下划线的TextBox

     public partial class UCTextBox : TextBox
        {
            public UCTextBox()
            {
                InitializeComponent();

                this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);

                this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

                this.BorderStyle = BorderStyle.None;

            }

            public bool DrawLine
            {
                get { return this.m_DrawLine; }

                set { this.m_DrawLine = value; this.Invalidate(); }

            }

            private bool m_DrawLine = false;

            private const int WM_NCPAINT = 0x0085;

            private const int WM_CHAR = 0x0102;

            [System.Runtime.InteropServices.DllImport("user32.dll")]
            static extern IntPtr GetWindowDC(IntPtr hWnd);

            [System.Runtime.InteropServices.DllImport("user32.dll")]
            static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);

                if (m.Msg == 0xf || m.Msg == 0x133)
                {
                    if (this.DrawLine)
                    {
                        IntPtr hDC = GetWindowDC(m.HWnd);

                        if (hDC.ToInt32() == 0)
                        {
                            return;
                        }

                        Graphics g = Graphics.FromHdc(hDC);

                        Brush b = Brushes.Black;

                        Pen p = new Pen(b, 1);

                        Point p1 = new Point(0, this.Height - 1);

                        Point p2 = new Point(this.Width, Height - 1);

                        g.DrawLine(p, p1, p2);

                        m.Result = IntPtr.Zero;

                        ReleaseDC(m.HWnd, hDC);
                   
                    }
                }
            }

            private Color backColor = System.Drawing.SystemColors.Control;

            public override Color BackColor
            {
                get
                {
                    return backColor;
                }
                set
                {
                    backColor = value;

                    Invalidate();
                }
            }
        }

  • 相关阅读:
    oracle10G/11G官方迅雷下载地址合集(转载)
    Oracle数据库的登录以及常用数据导入查询
    Tomcat添加SSL网站证书配置
    SVN的安装与在IDEA中的配置
    01-Spring Boot配置文件详解
    微服务概况及注册中心搭建
    zk实现分布式锁
    ZooKeeper初识
    Reids集群知识
    redis初识
  • 原文地址:https://www.cnblogs.com/johnwonder/p/1675670.html
Copyright © 2011-2022 走看看