图像文件似乎不存在,即使它存在于目录中

时间:2019-02-07 10:20:30

标签: c# windows-forms-designer

因此,我正在尝试创建一种将根据需要创建PictureBoxes的方法,并且我尝试加载到Image上的特定图像正在发生错误;

  

类型为'System.IO.FileNotFoundException'的未处理异常   发生在System.Drawing.dll

其他信息:

  

\ students \ student \ 30232634 \ My Documents \ Visual Studio   2015 \ Projects \ WindowsFormsApplication4 \ WindowsFormsApplication4 \ bin \ Debug / Graphics / enemyAlien.png

代码为:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace WindowsFormsApplication4
{
    class Aliens : PictureBox
    {
        public string alienImage = "Enemy.png";
        public int alienCount = 30;
        public int posX { get; set; }
        public int posY { get; set; }
        public Aliens AlienSpawn()
        {
            Aliens picture = new Aliens();
            picture.Name = "pictureBox";
            picture.Size = new Size(64, 64);
            picture.Location = new Point(100, 100);
            picture.Image =Image.FromFile(Directory.GetCurrentDirectory()+"/Graphics/enemyAlien.png");
            return picture;
        }
    }
}

0 个答案:

没有答案