Reputation: 2729
I have an image "back.jpg" in the location: projectfolder/image/back.jpg and I'm trying to load the image on a picturebox. I'm trying the following code but It didn't work.
this.pictureBox.ImageLocation = @"\image\back.jpg";
If I have the Image in H:\back.jpg . The following code is working
this.pictureBox.ImageLocation = @"H:\back.jpg";
What's wrong with this code?this.pictureBox.ImageLocation = @"\image\back.jpg";
Upvotes: 1
Views: 7259
Reputation: 3770
Your path should be: @"..\..\image\av.jpg"
, because you're running your application from "Folder\bin\debug"
folder, and the image is 2 folders higher.
Your path @"\image\back.jpg"
means that your're referring the root folder, i.e. you're targeting at "H:\image\back.jpg".
The best pattern here would be:
this.pictureBox.ImageLocation = "back.jpg";
Upvotes: 3
Reputation: 13296
Set the image file to be copied to the output directory always and refer to it only with the file name.
Upvotes: 0