public partial class mGroupBox : GroupBox { private Color _TitleBackColor = Color.Black; private Font _TitleFont = new Font("微软雅黑", 9F, FontStyle.Bold); private Color _TitleForeColor = Color.FromArgb(23, 169, 254); [Description("标题栏背景颜色"), Category("外观")] public Color TitleBackColor { get { return _TitleBackColor; } set { _TitleBackColor = value; Invalidate(); } } [Description("标题栏文字颜色"), Category("外观")] public Color TitleForeColor { get { return _TitleForeColor; } set { _TitleForeColor = value; Invalidate(); } } [Description("标题栏文字样式"), Category("外观")] public Font TitleFont { get { return _TitleFont; } set { _TitleFont = value; Invalidate(); } } //重绘 protected override void OnPaint(PaintEventArgs e) { int FontH = _TitleFont.Height + 2; //绘制填充 var titleSoild = new SolidBrush(_TitleBackColor); e.Graphics.FillRectangle(titleSoild, 0, 0, Width, FontH); var bodySolid = new SolidBrush(BackColor); e.Graphics.FillRectangle(bodySolid, 1, FontH, Width, Height); //绘制标题文字 var titleTextSoild = new SolidBrush(_TitleForeColor); e.Graphics.DrawString(Text, _TitleFont, titleTextSoild, 5, 1); } }