When I try to add a resource at the resource designer by clicking "Add an existing item",the item is placed in the folder "Resource".
The problem is that if I create a new directory in the Resource directory and place the resources there,I get a compiler error that the files cannot be found.
I can't put all resources in one folder,because I have to add 2500 images and some of them match their names.
You do not need to add the images under the Resources folder. You can add the images to any folder you wish, and then set the build action for the images to "Embedded Resource". That way they will be compiled into the assembly as resources. I don't know if there are performance issues coming into play when it is a large number of images though...
Update: more in detail:
This will cause the image files to be compiled into the assembly as resources. Each file will be assigned a resource name following this pattern: <root namespace for the assembly>.<folder name>.<image file name>
. You can load an image using this code:
using(Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("<root namespace for the assembly>.<folder name>.<image file name>"))
{
pictureBox1.Image = Image.FromStream(stream);
}
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