Move this.pictureBox1.Image = objpictureboximage; after the InitializeComponent();
The components on the form has not been initialized until after InitializeComponent(); so the form doesn't know about the pictureBox1 control (yet)
Thanks,
Einar
>C# 3.0
>
>VS 2008
>
>Please help this .NET newbie who is drowning!
>
>I'm trying to instantiate a form (OK that's a VFP term, I know!) and change the picturebox image at the time it's created.
>
>This compiles OK, but crashes with this error:
>System.NullReferenceException: Object reference not set to an instance of an object.
>
>when I run it.
>
>Acecard is a resource that I can find with intellisense.
>
>
>
>Calling code:
> ChildForm1 formAce = new ChildForm1(global::UsingMDI.Properties.Resources.acecard);
>
>
>Class being called:
>
>public ChildForm1(Image objpictureboximage)
> {
> this.pictureBox1.Image = objpictureboximage;
> // set image to display in pictureBox
>
>
> InitializeComponent();
> }
>
>TIA
Semper ubi sub ubi.