Search code examples
c#winformsanimated-gif

Overlap two gif animations without getting System.IO.FileNotFoundException


Hello I am just trying to create one of my first games and for that I decided to use gif animations but somehow after clicking by mouse the application instead of changing animation collapses with single message not even in error bar saying:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll 

Code:

bool shoot = false;
    public Form1()
    {            
        InitializeComponent();           
    }
    private void timer1_Tick(object sender, EventArgs e)
    {
        ballon_grey.Location = new Point(ballon_grey.Location.X,ballon_grey.Location.Y - 5);        
    }
    private void ballon_grey_MouseClick(object sender, MouseEventArgs e)
    {
        shoot = true;
        if (shoot == true)
        {
            ballon_grey.Image = Image.FromFile("baloon_explosion.gif");
        }
    }

Solution

  • if its in your resources all you need is this:

    ballon_grey.Image = YourApplication.Properties.Resources.baloon_explosion;