SagiLow
SagiLow

Reputation: 6029

Can't make PictureBox to be visible- C#

I'm trying to use PictureBox object in order to display an image, but i get some "errors" . If i just add the PictureBox attributes (location, image, size, backColor etc... ) i don't see any image

I then read i need to add the PictureBox to the Form Controller.

I added it and yet, still nothing ... is there any priority of the layers (what in the back what in the front ?, how can i change it ?)

here is the attributes set of the PictureBox:

imageFile = new PictureBox();
imageFile.Top = 200;
imageFile.Left = 400;
imageFile.Height = 100;// furnitureSize.Height;
imageFile.Width = 100;// furnitureSize.Width;
imageFile.ImageLocation = (Application.StartupPath + "\\ball4.gif");
imageFile.Image = Image.FromFile(Application.StartupPath + "\\lamp3.jpg");
imageFile.Visible = true;
imageFile.BackColor = Color.Black;
imageFile.SizeMode = PictureBoxSizeMode.StretchImage;
ownerForm.Controls.Add(imageFile);
imageFile.Show();

Please help.

Upvotes: 0

Views: 2365

Answers (3)

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

You must define size to your picturebox

imageFile.ClientSize = new Size(100, 100);

Upvotes: 0

SagiLow
SagiLow

Reputation: 6029

The problem was as i thought ( the pictureBox wasn't in the front) adding : imageFile.BringToFront(); solved the issue

Thank you all.

Upvotes: 0

avi
avi

Reputation: 912

Hmm... are you sure you meant

ownerForm.Controls.Add(imageFile);

and not

this.Controls.Add(imageFile);

?

Upvotes: 1

Related Questions