2011-01-31 27 views
1

例如,我使用一個循環來創建具有特定參數的「鳥」對象列表。 但我也需要每個鳥物體在winform上有一個pictureBox,任何想法,我該怎麼做,即動態創建並稍後刪除一個pictureBox?C#,動態創建圖片框?

謝謝!

回答

1

僞代碼:

list<picturebox> 

Instantiate the one needed 

Initialize every picturebox that are needed 

Add them to the form (form.control.add) 

If needed remove them from the form, (form.control.remove) 
+0

這是僞,PictureBox,列表,Controls.Add,Controls.Remove。如果沒有首先實例化它,你無法初始化PictureBox。 :/ – 2011-01-31 16:11:24

+0

@基倫·約翰斯通,我會假設他/他會知道:-)但我仍然會加上它 – Fredou 2011-01-31 16:13:06

1

您可以創建一個新的PictureBox實例,設置其屬性,並將其添加到表單或面板的Controls集合中。