Download image from folder in solution?

I am trying to load an image from a folder in a solution, but I get an error message that was not found. What have I done wrong? The code below is in MainForm.cs, which is at the same level as the Resource folder. Help is limited! Thank!

 // Images
 Image imageCircle = Image.FromFile("Resources/circle.png");

 // Set deafult picture on start
 pictureBox1.Image = imageCircle;
+5
source share
3 answers

It always takes the path from where the executable is located (bin folder). Therefore, if you can access it using the full path, the problem will be solved. Or you can have a configuration item for the root folder. then access, for example Image.FromFile(rootFolder+ "Resources/circle.png");. In any case, this problem will not occur during deployment.

And if you use a resource file,

<projectName>.Properties.Resources.<ImageName>;

will return the image.

+5
source

:

MSDN, , MSDN Resource Designer.

Project properties resources

enter image description here

, .

.

Image imageCircle = YourPojectName.Properties.Resources.YourFileNameHere;

enter image description here

+12

The program runs in bin / debug (where all the DLL files are), put there Resources.

0
source

All Articles