1

I am trying add picture boxes dynamically. My code is as

PictureBox picture = new PictureBox
        {
            Name = "pictureBox",
            Size = new Size(100, 150),
            Location = new Point(14, 17),
            Visible=true
        };

        picture.ImageLocation = @"Image\80knhk00003.jpg";
        pnlDisplayImage.Controls.Add(picture);

I have created Images Folder in project and added this image. Still when I run my code I can see only red cross.

I tried doing google. And I am getting similar solutions only. I dont know what is wrong in my code.

Along with this if I am storing image file location in database then how can I display such images in picture box? Please help

1 Answer 1

2

You picture doesn't get copied to the binary folder.

Add the jpg file into the solution. Open it properties (right click on the file name - properties). Enable the Copy to Output Directory option. Also enable it for the Images folder.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok..thanks..this helped along with changing file location in code as: "..\Images\80knhk00003.jpg". But if I have stored file locations in sql database and I want to show these images in picture box how can I do it?
@user1181942: If the database contains the full path to the image you can just use that. The problem is that @"Image\80knnk00003.jpg" refers to a folder Image that needs to exist in the same folder as the executable.
@user1181942 Mark this post as question answer then

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.