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; ////// 線條顏色 /// 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); } } } } }
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、秀峰網(wǎng)絡(luò)推廣、小程序開發(fā)、秀峰網(wǎng)絡(luò)營銷、秀峰企業(yè)策劃、秀峰品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供秀峰建站搭建服務(wù),24小時服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.com
原文地址:http://blog.csdn.net/geovi/article/details/7399406