PictureBox not displaying the image

Baub picture Baub · Feb 14, 2014 · Viewed 22.5k times · Source

In my C# project I have used the Tools to add a PictureBox control. I have set the image location to a location of a PNG on our network and I am having the same trouble as others where if the images are moved from that directory then the image in my program will not display.

I'd like to embed the images into the EXE when it compiles so the images aren't dependent on the actual file being available on the network. I have found an article that says to make my image a resource in my project. I did that but when I try to use it, I see the error: stream is not a valid resource file.

I know this can be accomplished but I, so far, haven't found what I need to do.

How should I set this up? Because I obviously have the wrong setup now.

Answer

Karam Najjar picture Karam Najjar · Feb 14, 2014

Step1: RightClick on the Project

Step2: Select Properties.

Step3: Go to Resources tab.

Step4: Click on Add Resource Dropdown menu shown in below pic.

Step5: Select Add Existing File...

Step6: now select the file which you want to add as Resource from File Browse Dialog.

Step7: select the picture that is added and set the Persistence property to Embedded in .resx

then the picture is embedded with your application ;)

to access it

pictureBox1.Image = Properties.Resources.ImageName;