【问题标题】:Overlap two gif animations without getting System.IO.FileNotFoundException [closed]重叠两个 gif 动画而不会得到 System.IO.FileNotFoundException [关闭]
【发布时间】:2014-06-13 15:31:25
【问题描述】:

您好,我只是想创建我的第一个游戏,为此我决定使用 gif 动画,但不知何故,在通过鼠标单击后,应用程序而不是更改动画会崩溃,并出现一条消息,甚至在错误栏中也没有说:

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

代码:

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");
        }
    }

【问题讨论】:

  • System.IO.FileNotFoundException - 这很好解释。它找不到文件。根据您当前的代码,它将查看程序正在执行的目录(很可能是您项目中的 bin\debug)。
  • 您确认文件存在吗?您以多种方式拼写“气球”,但没有一个是正确的。
  • @Tim 两个 gif 文件都保存在项目文件/资源​​中
  • @DanielMann 这只是一个拼写错误。
  • 如果它在你的资源中你只需要这个 - ballon_grey.Image = YourApplication.Properties.Resources.baloon_explosion;

标签: c# winforms animated-gif


【解决方案1】:

如果它在您的资源中,您只需要这样:

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

【讨论】:

    猜你喜欢
    • 2021-05-13
    • 2012-01-30
    • 1970-01-01
    • 2013-08-28
    • 2013-11-18
    • 2022-01-19
    • 2019-12-29
    • 2012-05-16
    • 1970-01-01
    相关资源
    最近更新 更多