You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.9 KiB
C#

using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace CompressorXN_ControlLib
{
public partial class GroupBoxEx : GroupBox
{
public GroupBoxEx()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.Selectable, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}
/// <summary>
/// 边框颜色
/// </summary>
private Color _BorderColor = Color.Silver;
[Browsable(true), Description("边框颜色"), Category("自定义属性")]
public Color BorderColor
{
get { return _BorderColor; }
set
{
_BorderColor = value;
this.Invalidate();
}
}
/// <summary>
/// 重写Onpaint
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
var vSize = e.Graphics.MeasureString(this.Text, this.Font);
e.Graphics.Clear(this.BackColor);
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), 10, 1);
Pen vPen = new Pen(this._BorderColor);
e.Graphics.DrawLine(vPen, 1, vSize.Height / 2, 8, vSize.Height / 2);
e.Graphics.DrawLine(vPen, vSize.Width + 8, vSize.Height / 2, this.Width - 2, vSize.Height / 2);
e.Graphics.DrawLine(vPen, 1, vSize.Height / 2, 1, this.Height - 2);
e.Graphics.DrawLine(vPen, 1, this.Height - 2, this.Width - 2, this.Height - 2);
e.Graphics.DrawLine(vPen, this.Width - 2, vSize.Height / 2, this.Width - 2, this.Height - 2);
}
}
}