I am having some problems inserting a image i have in my directory. I search through the resources I have on the internet and manage the relevant code to be use.
pictureArray[] > is a field
Created using this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class Field
{
public PictureBox picbox;
public Field()
{
picbox = null;
}
}
}
At the top of the code, i initalize it:
private Field[] pictureArray = new Field[100];
The portion of my code as following:
pictureArray[0].picbox = new PictureBox();
pictureArray[0].picbox.Image = System.Drawing.Image.FromFile(@"..\Postlogger\test.jpg");
pictureArray[0].picbox.Location = new System.Drawing.Point(17, 19);
pictureArray[0].picbox.Name = "picBox";
pictureArray[0].picbox.Size = new System.Drawing.Size(50, 50);
this.groupBox1.Controls.Add(pictureArray[0].picbox);
My image doesn’t appear on my screen. Any suggestion to what i have done wrongly?
Thanks!
I can see problem in your code 🙂
You have declared array of reference type
If you try and debug you will see all elements in
pictureArrayarenull. On the next line you are doingI believe it is throwing exception here as
pictureArray[0]isnull. Please instantiateFieldobject before referring it.This should work now.