C#中textbox的自定义样式没办法使用onpaint方法,因此需要截获windowmessage来重绘textbox,先设置textbox的边框为BorderStyle.FixedSingle,这样就可以辨别控件了 具体代码: protected override void WndProc(ref Message m) { base.WndProc(ref m); //Console.WriteLine(m.ToString() + "/n"); if (m.Msg == 0xf)/*|| m.Msg == 0x5*/ { IntPtr hDC = GetWindowDC(m.HWnd); if (hDC.ToInt32() == 0) { return; } //只有在边框样式为FixedSingle时自定义边框样式才有效 if (this.BorderStyle == BorderStyle.FixedSingle) { //设置刷新率 this.SetStyle( ControlStyles.DoubleBuffer|ControlStyles.ResizeRedraw, true); //边框Width为1个像素 System.Drawing.Pen pen = new Pen(Color.Aqua, 2); //绘制边框 System.Drawing.Graphics g = Graphics.FromHdc(hDC); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; System.Drawing.Drawing2D.GraphicsPath controlRegion = new GraphicsPath(); Point[] pl = new Point[5]; Point p = new Point(10, 0); pl[0] = p; p = new Point(10, this.Height - 15); pl[1] = p; p = new Point(0, this.Height); pl[2] = p; p = new Point(this.Width, this.Height); pl[3] = p; p = new Point(this.Width, 0); pl[4] = p; controlRegion.AddPolygon(pl); this.Region = new Region(controlRegion); g.DrawPath(pen, controlRegion); //g.DrawPolygon(pen, pl); pen.Dispose(); this.Update(); } //返回结果 m.Result = IntPtr.Zero; //释放 ReleaseDC(m.HWnd, hDC); } }