zoukankan      html  css  js  c++  java
  • 【原创】重绘winform的GroupBox

    功能:重绘winform的GroupBox,以便调整边框颜色和边框宽度
    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.SystemColors.GradientActiveCaption;
            /// <summary>
            /// 边框线颜色
            /// </summary>
            public Color BorderLineColor
            {
                get { return borderLineColor; }
                set { borderLineColor = value; }
            }
    
            private float borderLineWidth = 1;
            /// <summary>
            /// 边框线宽度
            /// </summary>
            public float BorderLineWidth
            {
                get { return borderLineWidth; }
                set { borderLineWidth = value; }
            }
    
            public Ctrl_GroupBox()
            {
                InitializeComponent();
            }
    
            protected override void OnPaint(PaintEventArgs e)
            {
                //base.OnPaint(e);
    
                e.Graphics.Clear(base.BackColor);
    
                //圆弧直径长度
                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);
    
                //左上角圆弧
                e.Graphics.DrawArc(pen, new Rectangle(0, (int)(titleHeight / 2), radius, radius), 180, 90);
    
                //上边框,标题前半部分
                e.Graphics.DrawLine(pen, radius / 2, (titleHeight - 1) / 2, radius + titleStartX-3, (titleHeight - 1) / 2);
    
                //画笔
                SolidBrush brush = new SolidBrush(Color.Black);
                Font font = new System.Drawing.Font("宋体", 10, FontStyle.Bold);
                //标题
                e.Graphics.DrawString(base.Text, font, brush, radius / 2 + titleStartX, 0);
    
                //上边框,标题右半部分
                e.Graphics.DrawLine(pen, radius / 2 + titleStartX + titleWidth+3, (titleHeight - 1) / 2, (width - 1) - radius / 2, (titleHeight - 1) / 2);
    
                //右上角圆弧
                e.Graphics.DrawArc(pen, new Rectangle((width - 1) - radius, (int)(titleHeight / 2), radius, radius), 270, 90);
    
                //右边框
                e.Graphics.DrawLine(pen, width - 1, (int)(titleHeight / 2) + radius / 2, width - 1, (height - 1) - radius / 2);
    
                //右下角圆弧
                e.Graphics.DrawArc(pen, new Rectangle((width - 1) - radius, (height - 1) - radius, radius, radius), 0, 90);
    
                //下边框
                e.Graphics.DrawLine(pen, (width - 1) - radius / 2, height - 1, radius / 2, height - 1);
    
                //左下角圆弧
                e.Graphics.DrawArc(pen, new Rectangle(0, (height - 1) - radius, radius, radius), 90, 90);
    
                //左边框
                e.Graphics.DrawLine(pen, 0, (height - 1) - radius / 2, 0, (int)(titleHeight / 2) + radius / 2);
            }
        }
    }
    
    
    

      

     
  • 相关阅读:
    删除指定目录下的文件及子文件
    PHP简单实现“相关文章推荐”功能的方法(此方法不是自创)
    微信开发中自动回复(扫码、关注推事件)
    方式三(API方式)C++手动加载CLR运行托管程序(CLR Hosting)
    分享 N种方法使用C++调用C#.NET库
    redis 持久化之 RDB & AOF
    redis 慢查询、Pipeline
    redis 发布订阅、geo、bitmap、hyperloglog
    redis5.0 数据结构与命令
    Linux 下安装 redis5.0
  • 原文地址:https://www.cnblogs.com/venux/p/4894447.html
Copyright © 2011-2022 走看看