溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

WinForm TextBox 下面橫線展示

發(fā)布時間:2020-08-06 11:21:19 來源:網(wǎng)絡(luò) 閱讀:763 作者:Misy 欄目:編程語言
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace WindowsFormsApplication1
{
    [ToolboxItem(true)] 
    public partial class TextBoxLine : TextBox
    {
        public TextBoxLine()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.BorderStyle = BorderStyle.None;  
        }

        public TextBoxLine(IContainer container)
        {
            container.Add(this);

            InitializeComponent();

            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.BorderStyle = BorderStyle.None;  
        }

        private bool m_DrawLine = false;
        public bool DrawLine
        {
            get
            {
                return this.m_DrawLine;
            }
            set
            {
                this.m_DrawLine = value;
                this.Invalidate();
            }
        }
        private Color _linecolor = Color.Black;
        /// <summary>
        /// 線條顏色
        /// </summary>
        public Color LineColor
        {
            get
            {
                return this._linecolor;
            }
            set
            {
                this._linecolor = value;
                this.Invalidate();
            }
        }

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

        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);
                    Pen p = new Pen(this._linecolor, 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);
                }
            }
        }
    }
}


原文地址:http://blog.csdn.net/geovi/article/details/7399406

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI