C# groupbox 改变颜色 paint事件
程序员文章站
2022-06-08 16:14:36
...
groupbox1改变边框颜色
private void groupBox1_Paint(object sender, PaintEventArgs e)
{
GroupBox gBox = (GroupBox)sender; //获取当前的groupbox
e.Graphics.Clear(gBox.BackColor); //清除当前groupbox的所有的颜色(字体和边框)
e.Graphics.DrawString(gBox.Text, gBox.Font, Brushes.Red, 10, 1); //设置group的text颜色为红色
var vSize = e.Graphics.MeasureString(gBox.Text, gBox.Font); //获取groupbox的大小
e.Graphics.DrawLine(Pens.Black, 1, vSize.Height / 2, 8, vSize.Height / 2);//画出字体左边的边框。黑色
e.Graphics.DrawLine(Pens.Red, vSize.Width + 8, vSize.Height / 2, gBox.Width - 2, vSize.Height / 2);//画出字体右边的边框。红色
e.Graphics.DrawLine(Pens.Yellow, 1, vSize.Height / 2, 1, gBox.Height - 2);//画出左边边框。黄色
e.Graphics.DrawLine(Pens.Blue, 1, gBox.Height - 2, gBox.Width - 2, gBox.Height - 2);//画出底部边框。蓝色
e.Graphics.DrawLine(Pens.Green, gBox.Width - 2, vSize.Height / 2, gBox.Width - 2, gBox.Height - 2);//画出右边边框。绿色
}
上一篇: Winform窗体移动
下一篇: # WinForm关闭窗体确认