【发布时间】:2019-11-21 20:05:36
【问题描述】:
我有一个绘制椭圆的函数。当通过更改表单大小绘制新椭圆时,我想通过将其颜色更改为与其背景相同的颜色来使先前绘制的椭圆不可见。
这是我在课堂上的功能:
class ClassClock
{
public static void drawClock(Point m, int s, Form frm, Color myColor)
{
Graphics paper = frm.CreateGraphics();
Pen myPen = new Pen(myColor);
int w = frm.ClientSize.Width;
int h = frm.ClientSize.Height;
m = new Point(w / 2, h / 2);
s = Math.Min(w, h) / 2;
paper.DrawEllipse(myPen, m.X - s, m.Y - s, s * 2, s * 2);
}
}
这是我的计时器:
private void timer1_Tick(object sender, EventArgs e)
{
ClassClock.drawClock(m, s, this, this.BackColor);
ClassClock.drawClock(m, s, this, Color.Black);
}
有人可以帮我找到解决办法吗?
【问题讨论】:
-
您必须引用旧椭圆才能对其进行任何操作。
-
您需要在
Paint事件处理程序中擦除旧椭圆并绘制新椭圆,而不是在Tick中。您的Tick处理程序应使新旧椭圆区域无效。