PictureBox控件pc1上面用g.DrawIcon在(200,200)位置画了一个32像素的图标,我要在该图标周围实现地震波/水波扩散效果(从里到外依次画5个半径增大的圈,先画内1圈,擦除内1圈后画内2圈,擦除内2圈消失后画内3圈,依次类推循环),请问如何实现?

解决方案 »

  1.   

    加一个System.Windows.Forms.Timer。
    在Timer的触发的时候,增加半径,并调用pictureBox.Invalidate()。
    Invalidate会触发pictureBox的重画。
    在重画中,按照半径画圆,然后在圆心DrawIcon。
      

  2.   

    Graphics g = null;
    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        try
        {
            if (g == null)
            {
                 g = e.Graphics;
            }  
        }
        catch (Exception ex)
        {
        }
    }
    private void timer1_Tick(object sender, EventArgs e)
    {
        try
        {               
            Pen penBrash = new Pen(Color.Green, 1);    //定义一绿色画笔
            Rectangle rg = new Rectangle(100, 100, 50, 50);
            g.DrawEllipse(penBrash, rg);            //画空心圆
        }
        catch (Exception ex)
        {             
        }
    }
    为什么定时器第一次执行到g.DrawEllipse(penBrash, rg);语句就弹出异常”ex = {"参数无效。"}“
       在 System.Drawing.Graphics.CheckErrorStatus(Int32 status)
       在 System.Drawing.Graphics.DrawEllipse(Pen pen, Int32 x, Int32 y, Int32 width, Int32 height)
       在 System.Drawing.Graphics.DrawEllipse(Pen pen, Rectangle rect)
       在 Pic.Form1.timer1_Tick(Object sender, EventArgs e) 位置 D:\test\Form1.cs:行号 67
      

  3.   

    不要缓存Graphics,而是在pictureBox1_Paint中绘图。Timer触发绘图就可以了:
    private void timer1_Tick(object sender, EventArgs e)
    {
       radius += 30;
       pictureBox1.Invalidate();   //<---
    }