Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

 

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?

  • Leaders
Posted

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

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...