I'm trying to load an image from a folder in the solution, but I only get a error message that it's not found. What have I done wrong? The code below is in the MainForm.cs that is at the same level as the Resource folder. Help is preciated! Thanks!
// Images
Image imageCircle = Image.FromFile("Resources/circle.png");
// Set deafult picture on start
pictureBox1.Image = imageCircle;
Edit: Fixed Broken Links
Take a look at this MSDN article, it discusses Adding and Editing Resources and what your options are, and this MSDN article discussing Linked and Embedded resources using the Resource Designer.
Then select your file
Then you can access it like Madurika suggests.
i.e.
Image imageCircle = YourPojectName.Properties.Resources.YourFileNameHere;
It always take the path from the where executable is located(bin folder). So if you can access it using full path, problem will solved. Or you can have a configuration item for the root folder. then access like Image.FromFile(rootFolder+ "Resources/circle.png");
. Anyway this issue wont be there when you deploy it.
And if you are using resource file,
<projectName>.Properties.Resources.<ImageName>;
will return the image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With