usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Diagnostics;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Drawing;namespaceWindowsFormsApplication1{[ToolboxItem(true)]publicpartialclassTextBoxLine:TextBox{publicTextBoxLine(){InitializeComponent();this.SetStyle(ControlStyles.DoubleBuffer,true);this.BorderStyle=BorderStyle.None;}publicTextBoxLine(IContainercontainer){container.Add(this);InitializeComponent();this.SetStyle(ControlStyles.DoubleBuffer,true);this.BorderStyle=BorderStyle.None;}privateboolm_DrawLine=false;publicboolDrawLine{get{returnthis.m_DrawLine;}set{this.m_DrawLine=value;this.Invalidate();}}privateColor_linecolor=Color.Black;///<summary>///线条颜色///</summary>publicColorLineColor{get{returnthis._linecolor;}set{this._linecolor=value;this.Invalidate();}}[System.Runtime.InteropServices.DllImport("user32.dll")]staticexternintReleaseDC(IntPtrhWnd,IntPtrhDC);[System.Runtime.InteropServices.DllImport("user32.dll")]staticexternIntPtrGetWindowDC(IntPtrhWnd);protectedoverridevoidWndProc(refMessagem){base.WndProc(refm);if(m.Msg==0xf||m.Msg==0x133){if(this.DrawLine){IntPtrhDC=GetWindowDC(m.HWnd);if(hDC.ToInt32()==0){return;}Graphicsg=Graphics.FromHdc(hDC);Penp=newPen(this._linecolor,1);Pointp1=newPoint(0,this.Height-1);Pointp2=newPoint(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