• 加下划线的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();
                }
            }
        }

  • 相关阅读:
    条件注释判断IE版本
    win7及以上系统打开chm空白或显示"无法打开"的2个解决方案
    复制和删除txt文件
    casperjs 抓取爱奇艺高清视频
    chrome扩展程序之http/https 报文拦截
    bootstrap 的 datetimepicker 结束时间大于开始时间
    Jquery EasyUI的datagrid页脚footer使用及数据统计
    Web应用程序在加入反向代理服务器的时候如何获得真实IP
    c#4.0 新特性 可选参数 可曾用过?
    Pyhon
  • 原文地址:https://www.cnblogs.com/johnwonder/p/1675670.html
Copyright © 2020-2023  润新知