简体   繁体   中英

How to resume picturebox image's gif winforms C#

When a specific condition is met I disable my picturebox and the image freeze's, whenever it runs again the gif starts all over again not from where it was stopped is there anyway to resume it ?

Stopping picturebox : http://prntscr.com/b6gg7a "Resuming" picturebox : http://prntscr.com/b6gglb

I believe indeed this is a rather tedious/unlikely to perform with an animated gif.

What you could/should do IMO is the following:

Instead of making the background a gif, break it into multiple frames(pictures). Set up a timer that triggers the background to change to the next image. You can pause and resume that timer the same as you would enable and disable the picturebox.

Your background change function could look something like this:

int bgCount = 8; //Amount of frames your background uses
int bgCurrent = 0;
string[] bgImg = {
    "bg1.png",
    "bg2.png",
    "bg3.png",
    "bg4.png",
    "bg5.png",
    "bg6.png",
    "bg7.png",
    "bg8.png",
};
        void changeBG()
{
    if(bgCurrent > bgCount-1) //If not displaying the last background image go to the next one
    {
        bgCurrent++;
        imgBox.image = bgImg[bgCurrent];
    }else //If displaying the last background image -> Start with the first one
    {
        bgCurrent = 0;
        imgBox.image = bgImg[bgCurrent];
    }
}
}

And you just let the timer trigger this event. And you simply start and stop the timer.

Sidenote:

1* You might experiment with, instead of changing the source, just make 8 imageboxed and call/display them as they are needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM