c# 怎样重画控件的风格
3个回答
展开全部
要上代码吗?我有个例子给你
重绘GroupBox的一段代码给你了
private void groupBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(groupBox1.BackColor);
Rectangle Rtg_LT = new Rectangle();
Rectangle Rtg_RT = new Rectangle();
Rectangle Rtg_LB = new Rectangle();
Rectangle Rtg_RB = new Rectangle();
Rtg_LT.X = 0; Rtg_LT.Y = 7; Rtg_LT.Width = 10; Rtg_LT.Height = 10;
Rtg_RT.X = e.ClipRectangle.Width - 11; Rtg_RT.Y = 7; Rtg_RT.Width = 10; Rtg_RT.Height = 10;
Rtg_LB.X = 0; Rtg_LB.Y = e.ClipRectangle.Height - 11; Rtg_LB.Width = 10; Rtg_LB.Height = 10;
Rtg_RB.X = e.ClipRectangle.Width - 11; Rtg_RB.Y = e.ClipRectangle.Height - 11; Rtg_RB.Width = 10; Rtg_RB.Height = 10;
//Color color = Color.FromArgb(51, 94, 168);
Color color = Color.Black;
Pen Pen_AL = new Pen(color, 1);
Pen_AL.Color = color;
Brush brush = new HatchBrush(HatchStyle.Divot, color);
e.Graphics.DrawString(groupBox1.Text, groupBox1.Font, brush, 6, 0);
e.Graphics.DrawArc(Pen_AL, Rtg_LT, 180, 90);
e.Graphics.DrawArc(Pen_AL, Rtg_RT, 270, 90);
e.Graphics.DrawArc(Pen_AL, Rtg_LB, 90, 90);
e.Graphics.DrawArc(Pen_AL, Rtg_RB, 0, 90);
e.Graphics.DrawLine(Pen_AL, 5, 7, 6, 7);
e.Graphics.DrawLine(Pen_AL, e.Graphics.MeasureString(groupBox1.Text, groupBox1.Font).Width + 3, 7, e.ClipRectangle.Width - 7, 7);
e.Graphics.DrawLine(Pen_AL, 0, 13, 0, e.ClipRectangle.Height - 7);
e.Graphics.DrawLine(Pen_AL, 6, e.ClipRectangle.Height - 1, e.ClipRectangle.Width - 7, e.ClipRectangle.Height - 1);
e.Graphics.DrawLine(Pen_AL, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 7, e.ClipRectangle.Width - 1, 13);
}
重绘GroupBox的一段代码给你了
private void groupBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(groupBox1.BackColor);
Rectangle Rtg_LT = new Rectangle();
Rectangle Rtg_RT = new Rectangle();
Rectangle Rtg_LB = new Rectangle();
Rectangle Rtg_RB = new Rectangle();
Rtg_LT.X = 0; Rtg_LT.Y = 7; Rtg_LT.Width = 10; Rtg_LT.Height = 10;
Rtg_RT.X = e.ClipRectangle.Width - 11; Rtg_RT.Y = 7; Rtg_RT.Width = 10; Rtg_RT.Height = 10;
Rtg_LB.X = 0; Rtg_LB.Y = e.ClipRectangle.Height - 11; Rtg_LB.Width = 10; Rtg_LB.Height = 10;
Rtg_RB.X = e.ClipRectangle.Width - 11; Rtg_RB.Y = e.ClipRectangle.Height - 11; Rtg_RB.Width = 10; Rtg_RB.Height = 10;
//Color color = Color.FromArgb(51, 94, 168);
Color color = Color.Black;
Pen Pen_AL = new Pen(color, 1);
Pen_AL.Color = color;
Brush brush = new HatchBrush(HatchStyle.Divot, color);
e.Graphics.DrawString(groupBox1.Text, groupBox1.Font, brush, 6, 0);
e.Graphics.DrawArc(Pen_AL, Rtg_LT, 180, 90);
e.Graphics.DrawArc(Pen_AL, Rtg_RT, 270, 90);
e.Graphics.DrawArc(Pen_AL, Rtg_LB, 90, 90);
e.Graphics.DrawArc(Pen_AL, Rtg_RB, 0, 90);
e.Graphics.DrawLine(Pen_AL, 5, 7, 6, 7);
e.Graphics.DrawLine(Pen_AL, e.Graphics.MeasureString(groupBox1.Text, groupBox1.Font).Width + 3, 7, e.ClipRectangle.Width - 7, 7);
e.Graphics.DrawLine(Pen_AL, 0, 13, 0, e.ClipRectangle.Height - 7);
e.Graphics.DrawLine(Pen_AL, 6, e.ClipRectangle.Height - 1, e.ClipRectangle.Width - 7, e.ClipRectangle.Height - 1);
e.Graphics.DrawLine(Pen_AL, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 7, e.ClipRectangle.Width - 1, 13);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询