Files
lserp_cs_6.0/其他程序/xNewMyFormDesigner/LabelGroupBox.cs
T
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

90 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NewMyFormDesigner
{
public partial class LabelGroupBox : GroupBox
{
//边框和标题颜色
private Color GroupBoxColor = Color.Black;
[Browsable(true), Description("边框颜色"), Category("自定义分组")]
public Color BorderColor
{
get { return GroupBoxColor; }
set { GroupBoxColor = value; }
}
//标题位置
//left = 1,
//Center = 2,
//right = 3,
private int Position = 1;
public int TitlePosition
{
get { return Position; }
set { Position = value; }
}
public LabelGroupBox()
{
InitializeComponent();
}
public LabelGroupBox(IContainer container)
{
container.Add(this);
InitializeComponent();
}
// 重写 把控件重新绘制
protected override void OnPaint(PaintEventArgs e)
{
var vSize = e.Graphics.MeasureString(this.Text, this.Font);
e.Graphics.Clear(this.BackColor);
Pen vPen = new Pen(this.GroupBoxColor); // 用属性颜色来画边框颜色
if (Position == 2)
{
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.GroupBoxColor), (this.Width - vSize.Width) / 2, 1);//标题
e.Graphics.DrawLine(vPen, 1, vSize.Height / 2, (this.Width - vSize.Width) / 2, vSize.Height / 2);//上左
e.Graphics.DrawLine(vPen, (this.Width - vSize.Width) / 2 + vSize.Width, 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);//右
}
else if (Position ==3)
{
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.GroupBoxColor), this.Width - vSize.Width - 2, 1);//标题
e.Graphics.DrawLine(vPen, 1, vSize.Height / 2, this.Width - vSize.Width - 2, vSize.Height / 2);//上左
e.Graphics.DrawLine(vPen, this.Width - 4, 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);//右
}else
{
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.GroupBoxColor), 10, 1);//标题
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);//右
}
}
}
}