30

I don't know if I asked it right, but basically what happened is that I made a winform app which loads its image from the resource folder.

The problem is that when I build the project and get the exe and give it to a friend, he won't have that resource folder like I do, so he'll get an error saying missing file.

How can I somehow mix, or combine, or attach the image with my app?

7
  • Do you need to update the image, or allow users to add images? Or are these static images that will not change? Commented Jul 18, 2012 at 21:15
  • possible duplicate of Load image from resources in C# Commented Jul 18, 2012 at 21:18
  • @MystereMan I don't think it's a dup (or at least not of the one you mention). This question is about how to embed the image; the other one is how to load the image.
    – Beska
    Commented Jul 18, 2012 at 21:21
  • @MystereMan ThanX man, as you said, I'm not trying to load the image. About your Question, Yes, The user has the Ability to change the background image of the form. (There is a Theme ComboBox where the user selects a theme)
    – vexe
    Commented Jul 18, 2012 at 21:24
  • @Beska - True, so I guess I just answered his next obvious question ;) Commented Jul 18, 2012 at 21:25

2 Answers 2

35

App Properties Window

You need to add it to the project by navigating to the Properties Window and going to the resource tab and adding the image from there.

Alternatively, from the PictureBox Control you can import resource from your computer.

Option 2

5
  • 3
    You can also include the image in your project, and mark it's build type to be Embedded Resource. Commented Jul 18, 2012 at 21:28
  • 1
    agreed, but when I've done that it wasn't visible in the Resources Mgr Area. Commented Jul 18, 2012 at 21:30
  • @MystereMan so after I mark it, if i wanna load it, should I load it from the resource file ? I mean, should I do this: string path = "imagePath\\image.jpg"; and then load it like: BackGround = Image.FromFile(path);
    – vexe
    Commented Jul 18, 2012 at 21:35
  • so if do this, I don't have to send my friend the resource file with the exe right ?
    – vexe
    Commented Jul 18, 2012 at 21:43
  • no its embedded. you should send your friend what is in the 'bin' folder Commented Jul 19, 2012 at 2:04
5

If you don't need to update it in the future, compile your program with the Image property Build Action set to Embedded Resource. If you need to change it in the future, compile with property Build Action set to Content.

5
  • May I ask you where Can I reach that ?
    – vexe
    Commented Jul 18, 2012 at 21:28
  • just right click on the image file from the file explorer in visual studio and select properties, one of the properties is 'build action'. Change it to embedded resource or content. its default value is None.
    – Riccardo
    Commented Jul 18, 2012 at 21:33
  • Thank you so much :) but Can you tell me the difference between "Embedded Resource" and "Content" ?
    – vexe
    Commented Jul 18, 2012 at 21:39
  • @VeXe - Content does not embed the resource, Embedded Resource does. Commented Jul 18, 2012 at 22:10
  • If you want to change image once you made the build you can't do it if you marked the image as Embedded resource. Instead if you marked it as Content you can change whenever you want
    – Riccardo
    Commented Jul 19, 2012 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.