c# groupBox 带标题边框,标题居中,重写控件


private void groupBox1_Paint(object sender, PaintEventArgs e)
{
//背景颜色
e.Graphics.Clear(System.Drawing.SystemColors.Control);
SizeF fontSize = e.Graphics.MeasureString(groupBox1.Text, groupBox1.Font); //背景颜色
e.Graphics.DrawString(groupBox1.Text, groupBox1.Font, Brushes.Black, (groupBox1.Width - fontSize.Width) / 2, 1); e.Graphics.DrawLine(Pens.CornflowerBlue, 1, 7, (groupBox1.Width - fontSize.Width) / 2, 7); e.Graphics.DrawLine(Pens.CornflowerBlue, (groupBox1.Width + fontSize.Width) / 2 - 4, 7, groupBox1.Width - 2, 7); e.Graphics.DrawLine(Pens.CornflowerBlue, 1, 7, 1, groupBox1.Height - 2); e.Graphics.DrawLine(Pens.CornflowerBlue, 1, groupBox1.Height - 2, groupBox1.Width - 2, groupBox1.Height - 2); e.Graphics.DrawLine(Pens.CornflowerBlue, groupBox1.Width - 2, 7, groupBox1.Width - 2, groupBox1.Height - 2);
 
 
e.Graphics.DrawLine(Pens.CornflowerBlue, 1, 7, 1, groupBox1.Height - 2);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM