怎么改变groupbox 控件的边框线条的宽度 20philistine
2个回答
展开全部
自绘OnPaint
groupBox1.Paint += PaintBorderlessGroupBox;
private void PaintBorderlessGroupBox(object sender, PaintEventArgs p)
{
GroupBox box = (GroupBox)sender;
p.Graphics.Clear(SystemColors.Control);
p.Graphics.DrawString(box.Text, box.Font, Brushes.Black, 0, 0);
}
groupBox1.Paint += PaintBorderlessGroupBox;
private void PaintBorderlessGroupBox(object sender, PaintEventArgs p)
{
GroupBox box = (GroupBox)sender;
p.Graphics.Clear(SystemColors.Control);
p.Graphics.DrawString(box.Text, box.Font, Brushes.Black, 0, 0);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public partial class GroupBoxEx : GroupBox
{
private Color mBorderColor = Color.White;
private float nThickness = 1;
public Color BorderColor
{
get { return mBorderColor; }
set { mBorderColor = value; }
}
public float Thickness
{
get { return nThickness; }
set { nThickness = value; }
}
public GroupBoxEx()
{
InitializeComponent();
}
// 重写
protected override void OnPaint(PaintEventArgs e)
{
SizeF 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.mBorderColor,nThickness); // 用属性颜色来画边框颜色
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);
}
}
{
private Color mBorderColor = Color.White;
private float nThickness = 1;
public Color BorderColor
{
get { return mBorderColor; }
set { mBorderColor = value; }
}
public float Thickness
{
get { return nThickness; }
set { nThickness = value; }
}
public GroupBoxEx()
{
InitializeComponent();
}
// 重写
protected override void OnPaint(PaintEventArgs e)
{
SizeF 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.mBorderColor,nThickness); // 用属性颜色来画边框颜色
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);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询