I have created a picturebox within my panel and I would like to fill it up with an image locally.
this is what I have done so far and the following code is just a small part of my panel creation code.
PictureBox picture = new PictureBox
{
Name = "pictureBox",
Size = new Size(100, 50),
Location = new Point(14, 17)
};
p.Controls.Add(picture);
picture.ImageLocation = @"..\Image\1.jpg";
It does works but not fully as after I have launch my c# windows form application, it jus show a small white box with a red cross in the middle instead of the image. Any idea how to solve it?
This question is related to
c#
winforms
user-interface
if you provide a bad path or a broken link, if the compiler cannot find the image, the picture box would display an X icon on its body.
PictureBox picture = new PictureBox
{
Name = "pictureBox",
Size = new Size(100, 50),
Location = new Point(14, 17),
Image = Image.FromFile(@"c:\Images\test.jpg"),
SizeMode = PictureBoxSizeMode.CenterImage
};
p.Controls.Add(picture);
OR
PictureBox picture = new PictureBox
{
Name = "pictureBox",
Size = new Size(100, 50),
Location = new Point(14, 17),
ImageLocation = @"c:\Images\test.jpg",
SizeMode = PictureBoxSizeMode.CenterImage
};
p.Controls.Add(picture);
i'm not sure where you put images in your folder structure but you can find the path as bellow
picture.ImageLocation = Path.Combine(System.Windows.Forms.Application.StartupPath, "Resources\Images\1.jpg");
Source: Stackoverflow.com