【发布时间】: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