怎么让pictureBox.Paint += new PaintEventHandler(this.pictureBox_Paint);执行后使picturebox的背景还原
在picturebox里做圆形时钟,以下为部分代码privatevoidtimer1_Tick(objectsender,EventArgse){pictureBox1....
在picturebox里做圆形时钟,以下为部分代码
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Paint += new PaintEventHandler(this.pictureBox1_Paint);
pictureBox1.Invalidate();//只重新绘制pictureBox
}
private void pictureBox1_Paint(object sender, PaintEventArgs e){
int h = DateTime.Now.Hour;
int m = DateTime.Now.Minute;
int s = DateTime.Now.Second;
Graphics g = Graphics.FromImage(pictureBox1.Image);
//坐标中心平移
g.TranslateTransform((float)130 / 2.0f, (float)130 / 2.0f);
//时针
g.RotateTransform(30.0f * h + 30.0f * (float)(m / 60.0f));
g.DrawImage(img2, -img2.Width / 2, -img2.Height / 2, img2.Width, img2.Height);
g.RotateTransform(-30.0f * h - 30.0f * (float)(m / 60.0f));
//分针
g.RotateTransform(360.0f * (float)(m / 60.0f));
g.DrawImage(img3, -img3.Width / 2, -img3.Height / 2, img3.Width, img3.Height);
g.RotateTransform(-360.0f * (float)(m / 60.0f));
//秒针
g.RotateTransform((float)s * 360 / 60.0f);
g.DrawImage(img4, -img4.Width / 2, -img4.Height / 2, img4.Width, img4.Height);
g.RotateTransform(-(float)s * 360 / 60.0f);
//转轴
g.DrawImage(img5, -img5.Width / 2, -img5.Height / 2, img5.Width, img5.Height);
//坐标中心平移还原
g.TranslateTransform(-(float)130 / 2.0f, -(float)130 / 2.0f);
//表盖
g.DrawImage(img6, 0, 0, img1.Width, img1.Height);
}
运行后picturebox的图片每秒不断叠加 怎么解决?分不多都给了,麻烦解决下谢谢。 展开
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Paint += new PaintEventHandler(this.pictureBox1_Paint);
pictureBox1.Invalidate();//只重新绘制pictureBox
}
private void pictureBox1_Paint(object sender, PaintEventArgs e){
int h = DateTime.Now.Hour;
int m = DateTime.Now.Minute;
int s = DateTime.Now.Second;
Graphics g = Graphics.FromImage(pictureBox1.Image);
//坐标中心平移
g.TranslateTransform((float)130 / 2.0f, (float)130 / 2.0f);
//时针
g.RotateTransform(30.0f * h + 30.0f * (float)(m / 60.0f));
g.DrawImage(img2, -img2.Width / 2, -img2.Height / 2, img2.Width, img2.Height);
g.RotateTransform(-30.0f * h - 30.0f * (float)(m / 60.0f));
//分针
g.RotateTransform(360.0f * (float)(m / 60.0f));
g.DrawImage(img3, -img3.Width / 2, -img3.Height / 2, img3.Width, img3.Height);
g.RotateTransform(-360.0f * (float)(m / 60.0f));
//秒针
g.RotateTransform((float)s * 360 / 60.0f);
g.DrawImage(img4, -img4.Width / 2, -img4.Height / 2, img4.Width, img4.Height);
g.RotateTransform(-(float)s * 360 / 60.0f);
//转轴
g.DrawImage(img5, -img5.Width / 2, -img5.Height / 2, img5.Width, img5.Height);
//坐标中心平移还原
g.TranslateTransform(-(float)130 / 2.0f, -(float)130 / 2.0f);
//表盖
g.DrawImage(img6, 0, 0, img1.Width, img1.Height);
}
运行后picturebox的图片每秒不断叠加 怎么解决?分不多都给了,麻烦解决下谢谢。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询