【发布时间】:2016-02-04 10:23:13
【问题描述】:
这会生成一个图片框
PictureBox[][] picturebox;
public void loadPictureBox()
{
string path = @"../../Images/Catelogue/"; //set pathing
string[] list = Directory.GetFiles(path, "*.jpg");
//pictureboxCatelogue = new PictureBox[list.Length];
//pictureboxCosplay = new PictureBox[list.Length];
picturebox = new PictureBox[4][];
for (int i = 0; i < 4; i++)
{
picturebox[i] = new PictureBox[list.Length];
int y = 85, temp = 220, run = 0;
for (int index = 13; index < list.Length; index++) // loads all pictures and create pictureboxes
{
picturebox[i][index] = new PictureBox();
picturebox[i][index].Image = Image.FromFile(path + index + ".jpg");
this.Controls.Add(picturebox[i][index]);
temp = temp + 200;
if (index % 4 == 0)
{
if (run != 0)
y = y + 200;
run++;
temp = 220;
}
picturebox[i][index].Location = new Point(temp, y);
picturebox[i][index].Size = new Size(180, 180);
picturebox[i][index].Name = Convert.ToString(index);
picturebox[i][index].SizeMode = PictureBoxSizeMode.Zoom;
picturebox[i][index].BackColor = Color.FromArgb(35, 35, 35);
picturebox[i][index].Click += new System.EventHandler(PictureBox_Click);
}
}
}
我试图隐藏一个锯齿状数组,它是 winform c# 中的图片框,但我不断收到错误消息,是否可以隐藏锯齿状数组?这是我遇到问题的代码。
for (int i = 0; i < picturebox.Length; i++)
{
picturebox[0][i].Hide();
}
这是我得到的错误
错误:APPD 分配 2.exe 中出现“System.NullReferenceException”类型的第一次机会异常(附加信息:对象引用未设置为对象的实例。)
【问题讨论】: