【发布时间】:2015-07-07 17:50:58
【问题描述】:
我使用 GUI 创建了 64 个图片框。现在我想将这些图片框组合成一个图片框数组,因为我需要它不断更新所述图片框中的图片。
我有以下代码:
private PictureBox[] pictureBoxArray= new PictureBox[64]; //Initialize array to group picture boxes into picture box array
private void Main_Load(object sender, EventArgs e)
{
ConvertGuiPBtoGuiPbArray(ref pictureBoxArray);
}
public static void ConvertGuiPBtoGuiPbArray(ref PictureBox[] pictureBoxArray)
{
foreach(PictureBox index in pictureBoxArray)
{
//Some code to do the following:
pictureBoxArray[0]=pictureBox1; //this is the name of the pictureBox on the GUI
pictureBoxArray[1]=pictureBox2;
pictureBoxArray[2]=pictureBox3;
.
.
.
pictureBoxArray[63]=pictureBox64;
//
}
我见过 Controls.ofType 的命令,但我似乎不明白。任何建议将不胜感激。我在这里先向您的帮助表示感谢!
【问题讨论】:
-
为什么会出现在 foreach 语句中?
-
因为我必须遍历整个数组(?)(只是一个建议,欢迎任何更改)
-
我还是不明白你的问题,你想要更好的方式来编写你的代码还是你想用你的代码做其他事情?
-
另外,您的参数不需要 ref,数组是一个类,默认为 ref。
标签: c# arrays winforms picturebox