c# groupbox 标题居中,并修改边框颜色

private void groupBox1_Paint(object sender, PaintEventArgs e) {
   e.Graphics.Clear(groupBox1.BackColor);
   SizeF fontSize = e.Graphics.MeasureString(groupBox1.Text, groupBox1.Font);
   e.Graphics.DrawString(groupBox1.Text, groupBox1.Font, Brushes.MediumBlue, (groupBox1.Width - fontSize.Width) / 2, 1);
   e.Graphics.DrawLine(Pens.MediumBlue, 1, 10, (groupBox1.Width - fontSize.Width) / 2, 10);
   e.Graphics.DrawLine(Pens.MediumBlue, (groupBox1.Width + fontSize.Width) / 2 - 4, 10, groupBox1.Width - 2, 10);
}

你可能感兴趣的:(c# groupbox 标题居中,并修改边框颜色)