How can I use an animated GIF for Button-control?

This may be a stupid question, but it cannot solve the following problem. I put the gif animation on the button. But he is consistent and never stops. I need to stop him after completing one lap.

Bitmap boom = new Bitmap("boom.gif");
b[ship2.Column, ship2.Row].Image = boom;

What is wrong with my code?

+3
source share
3 answers

There is nothing wrong with the code.

The number of cycles is stored in the image metadata. So basically you need to provide a gif that has a loop disabled or edit it using some gif editor.

EDIT

gif , http://gif-explode.com/, gif. - :

  • gif
  • , .
  • gif
0

pictureBox ( )

ImageAnimator Class

// this starts animation 
System.Drawing.ImageAnimator.Animate(pictBox.Image, OnFrameChanged);

// this stops animation
System.Drawing.ImageAnimator.StopAnimate(pictBox.Image, OnFrameChanged);

private void OnFrameChanged(object sender, EventArgs e)
{
   // conditions
}
0

You can use a series of images instead of gifs. You can use the timer and set the interval to the desired speed. The timer will change the image of the button on each tick. For this you need a gif framework. You can go to → http://gif-explode.com/ . Put the gif there and get every frame. Then you can put the images in the image list. I assume that you want the animation to start when the button is clicked.

    int i = 0;
    private void timer1_Tick(object sender, EventArgs e)
    {
        if (i == imageList1.Images.Count)
        {
            timer1.Stop();
            i = 0;
        }

        button1.Image = imageList1.Images[i];
        i++;        
    }

    private void button1_Click(object sender, EventArgs e)
    {
        timer1.Start();
    } 
0
source

All Articles