C#再用代码设置控件时出错了,该怎么解决

  whiteBox[numberWhite] = new PictureBox();
                    whiteBox[numberWhite].Size = new Size(20,20);
                    whiteBox[numberWhite].SizeMode = Zoom;
                    whiteBox[numberWhite].Location = pointWhite[numberWhite];
                    whiteBox[numberWhite].Image = Properties.Resources.白子;
                    whiteBox[numberWhite].BackColor = Color.Transparent;
                                          return whiteBox[numberWhite];

看你具体是编译错了,还是运行错了,具体错误的行是在哪里。
比如whiteBox[numberWhite].SizeMode = Zoom; Zoom是什么类型的
whiteBox[numberWhite].Location = pointWhite[numberWhite]; 下标有没有越界
whiteBox[numberWhite].Image = Properties.Resources.白子; 资源有没有找到
等等,都可能出错。

你是在做五子棋么?有很多现成的
https://blog.csdn.net/steveliu13/article/details/50573831
https://www.jb51.net/article/133863.htm

应该是numberWhite未赋值导致的空对象问题

嗯,你可以线在界面上拖动一个按钮,然后看框架为此操作编写了哪些代码,仿照这些代码,你可以自己写一个控件,这样你就知道问题所在(是因为你写的代码不在特定的类中,还是控件初始化为空等待问题)

在windows 窗体界面,创建一个框架,找到所需要的windows窗体或公共控件,在相应的按钮下编写代码,看程序能否编译,根据编译错误提示,找错误原因。