C # PictureBox - can't make it work

I'm having trouble displaying a PictureBox in C #. I have two forms. In my main form, I call another form where the PictureBox is located.

This is how I call the second form:

frmODeck oDeck = new frmODeck(); oDeck.Show(); 

Now this is my second form, where the PictureBox is from the main form

 namespace Shuffle_Cards { public partial class frmODeck : Form { private PictureBox picBox; private Image image; public frmODeck() { InitializeComponent(); } private void frmODeck_Load(object sender, EventArgs e) { image = Image.FromFile("C:\\C2.jpg"); picBox = new PictureBox(); picBox.Location = new Point(75, 20); picBox.Image = image; picBox.Show(); } public void getCards() { } } } 

What am I doing wrong or what am I missing?

thanks

+4
source share
2 answers

The image control must be added to the top-level control collection to which it must belong - in the case, the form itself. Relevant: Control.Controls .

Replace:

 picBox.Show(); 

with:

 Controls.Add(picBox); 
+4
source

If you are doing picBox.Show () ;, you need to add it to the controls of the window you are loading, with @Ani code, provided:

 Controls.Add(picBox); 

That should do it!

0
source

All Articles