class MyCircle
{
int x; int y; int r;
public MyCircle(int x, int y, int r) { this.x = x; this.y = y; this.r = r; }
public override void Draw(Graphics g)
{
Random rd = new Random();
int red, blue, green;
red = rd.Next(255);
blue = rd.Next(255);
green = rd.Next(255);
Pen pen = new Pen(Color.FromArgb(red, blue, green), 2);
g.DrawEllipse(pen, x, y, r, r);
}
private void button1_Click(object sender, EventArgs e)
{
for (int s = 30; s <= 600; s++)
{
shapes = new MyCircle(x, s, r);
shapes.Draw(g);
System.Threading.Thread.Sleep(10);
在這裡重繪~~
}
}
你的代碼邏輯不對,你應該讓Paint事件去畫,而不是在Button裡畫,道理很簡單,即便你在按鈕事件中畫了,如果窗體被遮擋、最小化等等,畫上去的東西就沒有了。