"Original" Redraw WinForm's GroupBox

Source: Internet
Author: User
Tags border color

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.