.net Winform自定义渐变个性化的GroupBox

先看效果:

如图,上面使用了LinearGradientBrush。从而让GroupBox显得更为个性化。 

再看源码:

using CommonUtils.Controls.GroupControls;
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Collections.Generic;

namespace CommonUtils.Controls.GroupBoxControls
{
    /// <summary>A special custom rounding GroupBox with many painting features.</summary>
    [ToolboxBitmap(typeof(LinearGradientGrouper), "MyControls.Grouper.bmp")]
    [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
    public class LinearGradientGrouper : UserControl
    {
        #region Variables
        private System.ComponentModel.Container components = null;
        private int _RoundCorners = 10;
        private string _GroupTitle = "The Grouper";
        private Color _BorderColor = Color.Black;
        private float _BorderThickness = 1;
        private bool _ShadowControl = false;
        private Color _BackgroundColor = Color.White;
        private Color _BackgroundGradientColor = Color.White;
        private GroupBoxGradientMode _BackgroundGradientMode = GroupBoxGradientMode.None;
        private Color _ShadowColor = Color.DarkGray;
        private int _ShadowThickness = 3;
        private Image _GroupImage = null;
        private Color _CustomGroupBoxColor = Color.White;
        private bool _PaintGroupBox = false;
        private Color _BackColor = Color.Transparent;
        Color[] colors = new Color[] { Color.Red, Color.OrangeRed, Color.DarkRed, Color.DarkGoldenrod, Color.Orange, Color.Yellow, Color.White };
        #endregion

        #region Constructor

        /// <summary>This method will construct a new GroupBox control.</summary>
        public LinearGradientGrouper()
        {
            InitializeStyles();
            InitializeGroupBox();
        }

        #region Initialization

        /// <summary>This method will initialize the controls custom styles.</summary>
        private void InitializeStyles()
        {
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        }

        /// <summary>This method will initialize the GroupBox control.</summary>
        private void InitializeGroupBox()
        {
            components = new System.ComponentModel.Container();
            this.Resize += new EventHandler(GroupBox_Resize);
            this.DockPadding.All = 20;
            this.Name = "GroupBox";
            this.Size = new System.Drawing.Size(368, 288);
        }
        #endregion Initialization
        #endregion Constructor


        #region Properties

        /// <summary>This feature will paint the background color of the control.</summary>
        [Category("Appearance"), Description("This feature will paint the background color of the control.")]
        public override Color BackColor
        {
            get { return _BackColor; }
            set { _BackColor = value; this.Refresh(); }
        }

        /// <summary>This feature will paint the group title background to the specified color if PaintGroupBox is set to true.</summary>
        [Category("Appearance"), Description("This feature will paint the group title background to the specified color if PaintGroupBox is set to true.")]
        public Color CustomGroupBoxColor
        {
            get { return _CustomGroupBoxColor; }
            set { _CustomGroupBoxColor = value; this.Refresh(); }
        }

        /// <summary>This feature will paint the group title background to the CustomGroupBoxColor.</summary>
        [Ca
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值