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