我想知道如何使用代碼創建對象。我已經開始用這樣的如何動態創建對象?
object ns = new PictureBox();
ns.BackgroundImage = Properties.Resources.myImage;
但是,編譯器給我一個錯誤:
'object' does not contain a definition for 'BackgroundImage' and no extension method 'BackgroundImage' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
如果我刪除最後一行,它編譯,但出現的窗口上什麼都沒有。
'PictureBox ns = new PictureBox();'?你爲什麼試圖像那樣創造它? – 2014-09-29 23:42:23
或者簡單地使用'var ns = ...'。 – paqogomez 2014-09-29 23:47:05