Resource Images

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
In my C# Project, I have added a couple hundred images by "drag-n-drop"-ing them into to the Properties.Resources section. All of these images were in an "images" folder of my Project on my computer. Currently, the Solution Explorer displays all of these images in an "images" folder that it created after my "drag-n-drop" operation.

Now: How do I *get* these images for my code?

I have a PictureBox named "pbImage" on my main form that needs to display these at various times, but my call to GetManifestResourceStream() always returns null.

I am concerned that the string "imageName" may not be correct, but I can not seem to find the wording that C# is looking for.

Code:
private void Set_Image(String imageName)
{
Assembly gExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream gImage;
String[] name = gExe.GetManifestResourceNames();
String image = name[0] + "." + imageName;
gExe = System.Reflection.Assembly.GetExecutingAssembly();
try
{
	gImage = gExe.GetManifestResourceStream(image); // returns null
	pbImage.Image = Image.FromStream(gImage); // causes exception
}
catch (Exception ex)
{
	Console.WriteLine("Exception Message: {0}", ex.Message);
}
}

Any ideas?
 
Assuming that you are using 2005, if the project has added them to the resources pseudo-folder for you, you should be able to access them like following:

DefaultNamespace.Properties.Resources.ResourceName
 
Back
Top