我需要在c#windows应用程序
中为对象设置动画int l_nCircleXpos = 9, l_nCircleYpos = 0;
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics l_objGraphics = this.CreateGraphics();
Pen l_circlePen = new Pen(Color.Blue);
SolidBrush l_circleBrush = new SolidBrush(Color.Blue);
l_objGraphics.DrawEllipse(l_circlePen, l_nCircleXpos, l_nCircleYpos, 30, 30);
l_objGraphics.FillEllipse(l_circleBrush, l_nCircleXpos, l_nCircleYpos, 30, 30);
Pen l_rectPen = new Pen(Color.Red);
}
private void timer1_Tick(object sender, EventArgs e)
{
l_nCircleXpos++;
l_nCircleYpos++;
}
private void timer2_Tick(object sender, EventArgs e)
{
Invalidate();
}
但是在timer2中它使整个表单无效。我只需要使特定的圆圈区域无效。
请以更好的方式帮助您做到这一点
答案 0 :(得分:2)
您可以将Rectangle
(或更好,Region
)作为参数传递给Invalidate
,以使您需要刷新的区域无效:
Region region = /* region you need to refresh */;
this.Invalidate(region);