views:

60

answers:

2

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

This is how I am calling the second form:

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

Now, this is my second form, where the PictureBox is located from 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

+3  A: 

The picture-box control needs to be added to the control-collection of the top-level control it should belong to - in the case, the form itself. Relevant: Control.Controls.

Replace:

picBox.Show();

with:

Controls.Add(picBox);
Ani
Thanks a lot, it's working now
Esau Silva
A: 

Befor you do a picBox.Show(); , you need to add it to the Controls of the window you are loading, with the code @Ani provided:

Controls.Add(picBox);

That should do it!

David Conde
Thanks a lot to both, it's working now
Esau Silva