我想知道如何使用代码创建对象。我已经开始用这样的如何动态创建对象?
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