這是假設使用PictureBox的匹配遊戲,但我一直收到一個錯誤,無法將類型'object
'隱式轉換爲'System.Drawing.Image
'。而且我不知道如何從那裏繼續。如何使用數組和圖片框來顯示圖像
void Form1_Load(object sender, EventArgs e)
{
ArrayList images = new ArrayList();
{
images.Add(Image.FromFile(Application.StartupPath + "\\MGG1.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG2.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG3.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG4.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG5.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG6.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG7.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG8.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG9.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG10.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG11.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG12.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG13.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG14.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG15.png"));
images.Add(Image.FromFile(Application.StartupPath + "\\MGG16.png"));
}
Random r = new Random();
A1.Image = images[0];
}
請更新您的標題告訴人們你的問題是關於 – Liath
什麼這是一個很好的用於循環的地方。 – semao