Function: Redraw the GroupBox of the WinForm to adjust the border color and border width
Using system;using system.collections.generic;using system.componentmodel;using system.drawing;using System.Data; Using system.linq;using system.text;using system.windows.forms;using system.drawing.drawing2d;namespace JSHYSC_ ctrllib{public partial class Ctrl_groupbox:groupbox {private Color borderlinecolor =system.drawing.system Colors.gradientactivecaption; <summary>///Border Line Color///</summary> public color Borderlinecolor {g ET {return borderlinecolor;} set {Borderlinecolor = value;} } private float borderlinewidth = 1; <summary>///Border line width///</summary> public float Borderlinewidth {g ET {return borderlinewidth;} set {borderlinewidth = value;} } public Ctrl_groupbox () {InitializeComponent (); } protected override void OnPaint (PaintEventArgs e) { Base. OnPaint (e); E.graphics.clear (base. BackColor); Arc diameter length int radius = 20; int width = e.cliprectangle.width, height = e.cliprectangle.height; int titlestartx = 15; float titlewidth = e.graphics.measurestring (base. Text, base. Font). Width; float titleheight = e.graphics.measurestring (base. Text, base. Font). Height; Pen pen = new Pen (borderlinecolor, (float) borderlinewidth); Upper left corner arc E.graphics.drawarc (pen, new Rectangle (0, (int) (TITLEHEIGHT/2), radius, radius), 180, 90); Top border, title front half e.graphics.drawline (pen, RADIUS/2, (titleHeight-1)/2, Radius + titleStartX-3, (titleheight -1)/2); Brushes SolidBrush Brush = new SolidBrush (color.black); Font font = new System.Drawing.Font ("Arial", ten, FontStyle.Bold); Title E.graphics.drawstring (base. Text, font, brush, RADIUS/2 + titlestartx, 0); Topbox, title right half E.graphics.drawline (pen, RADIUS/2 + Titlestartx + titlewidth+3, (titleHeight-1)/2, (width-1)- RADIUS/2, (titleHeight-1)/2); upper right corner arc E.graphics.drawarc (pen, New Rectangle ((width-1)-radius, (int) (TITLEHEIGHT/2), radius, radius), 27 0, 90); Right border E.graphics.drawline (pen, width-1, (int) (TITLEHEIGHT/2) + RADIUS/2, width-1, (height-1)-radius /2); Lower right corner arc E.graphics.drawarc (pen, New Rectangle ((width-1)-radius, (height-1)-radius, radius, radius), 0, 90); Bottom Border E.graphics.drawline (pen, (width-1)-RADIUS/2, Height-1, RADIUS/2, height-1); Lower left corner arc E.graphics.drawarc (pen, new Rectangle (0, (height-1)-radius, radius, radius), 90, 90); Left Border E.graphics.drawline (pen, 0, (height-1)-RADIUS/2, 0, (int) (TITLEHEIGHT/2) + RADIUS/2); } }}
"Original" Redraw WinForm's GroupBox