找不到图像路径文件

Dot*_*NET 1 .net c# filenotfoundexception visual-studio-2010 winforms

我花了很长时间试图解决这个问题,但无济于事.我已经搜索了stackoverflow以及Google,并且无法解决我(看似)简单的问题.

我在以下行中收到FileNotFoundException:

Image.FromFile("\\Resources\\Icons\\key-icon.png");
Run Code Online (Sandbox Code Playgroud)

文件夹和图像真的存在,我无法看到问题所在.

lor*_*ert 9

您应该考虑它是从"yourproject/bin/Release"启动的,因此您需要上升2个目录.做这个:

Image.FromFile("..\\..\\Resources\\Icons\\key-icon.png"); 
Run Code Online (Sandbox Code Playgroud)