Using Resource Images

P

poojo hackma

In my Project, I have added a couple hundred images using "drag-n-drop" to
the Properties.Resources section. All of these images were in the "images"
folder of my Project on my computer, and the Solution Explorer displays all
of the images in an "images" folder that it created after I dropped these
into the Resources section.

Now, how do I *get* these images for my code?

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

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

Here is the 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); // throws exception
}
catch (Exception ex)
{
Console.WriteLine("Exception Message: {0}", ex.Message);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top