2

I want PictureBox to load images from application folder. In the code below it loads picture from exact place. I want it to load images from application's folder so that if I copy it to other computers it could load images.

How can I do it?

Loads from exact place:

PictureBox1.Image = Image.FromFile("D:\68.jpg");

I want it to be like this:

PictureBox1.Image = Image.FromFile("ApplicationFolder\68.jpg");
1

2 Answers 2

4

Using the info in the comment above, you could do:

PictureBox1.Image = Image.FromFile(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "68.jpg"))

To do use a subdirectory of the assembly base directory:

PictureBox1.Image = Image.FromFile(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SomeFolderInBaseDirectory", "68.jpg"))
2
  • Thanks.It works.Also I wanted to ask if I can call images from folder inside the BaseDirectory so that they don't mix with .exe files? Commented Mar 13, 2013 at 18:52
  • @MuradTalibov Please accept as answer if it solved your issue (which according to your comment it did).
    – codechurn
    Commented May 30, 2013 at 2:33
0

Use to keep images in application resources:

Add PictureBox control on Form. Select the control on the form and use properties. Find Image under the Appearance section in Properties tab and click on [...]. Select Resource dialog imports all images you're going to use in your application. Then remove the PictureBox from the Form. The application keeps all images in resources

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