Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将多个图像设置为多个PictureBox_C#_Image_Picturebox - Fatal编程技术网

C# 将多个图像设置为多个PictureBox

C# 将多个图像设置为多个PictureBox,c#,image,picturebox,C#,Image,Picturebox,我打算做的是 PictureBox1.Image = ImageHere 但我不知道除了那个时候,我将如何在弥撒上进行这件事 PictureBox2.Image = ImageHere2 PictureBox3.Image = ImageHere3 PictureBox4.Image = ImageHere4 如果我可以执行[increment]或其他操作,但遭到拒绝,您可以动态创建PictureBox并为其分配相应的值 如果要将图片框和图像放入数组或类似的数组中,可以这样循

我打算做的是

  PictureBox1.Image = ImageHere
但我不知道除了那个时候,我将如何在弥撒上进行这件事

  PictureBox2.Image = ImageHere2
  PictureBox3.Image = ImageHere3
  PictureBox4.Image = ImageHere4

如果我可以执行[increment]或其他操作,但遭到拒绝,您可以动态创建PictureBox并为其分配相应的值

如果要将图片框和图像放入数组或类似的数组中,可以这样循环:

PictureBox[] pictureBoxes = { PictureBox1, PictureBox2, PictureBox3, PictureBox4 };
Image[] images = { ImageHere1, ImageHere2, ImageHere3, ImageHere4 };

for (int i = 0; i < pictureBoxes.Length; i++)
{
    pictureBoxes[i].Image = images[i];
}
PictureBox[]PictureBox={PictureBox1,PictureBox2,PictureBox3,PictureBox4};
Image[]images={ImageHere1,ImageHere2,ImageHere3,ImageHere4};
for(int i=0;i

但是创建数组仍然很麻烦。

创建图像列表并使用foreach迭代器:

List<Image> images = //get your list of images
foreach(var img in images)
{
    PictureBox pb = new PictureBox();
    pb.Image = img;
    YourControl.Add(pb);
}
List images=//获取图像列表
foreach(图像中的var img)
{
PictureBox pb=新PictureBox();
pb.Image=img;
YourControl.Add(pb);
}

我不知道您需要在何处显示您的picturebox。YourControl.Add-是您的Add方法到需要显示picturebx的控件中,而一旦pb在运行时创建,在您将其添加到控件中之前,它将不会显示在yur表单等上。是否有方法将图像添加到该图像数组中?别管^,谢谢你