先在panel容器(长宽为300)中绘制一个宫格,比如下面这样:
private void Form1_Load(object sender, EventArgs e)
{
this.InitRandomPictureBox();
}
private void InitRandomPictureBox()
{
this.pnl_Random.Controls.Clear();
for (int i = 0; i < this.ImgNumbers; i++)
{
for (int j = 0; j < this.ImgNumbers; j++)
{
PictureBox pic = new PictureBox();
pic.Location = new Point(j * this.SideLength, i * this.SideLength);
pic.Size = new Size(this.SideLength, this.SideLength);
pic.Visible = true;