1、界面设计
添加8个pictureBox和1个button控件,将它们按顺序排成九宫格的样式(button在中间)。
加载图片
int i = 0, rd, cnt = 0, a = 0;
PictureBox[] pic = new PictureBox[8]; //定义一个PictureBox的数组
private void Form1_Load(object sender, EventArgs e)
{
this.BackgroundImage = Properties.Resource1.背景;
button1.BackgroundImage = Properties.Resource1.按键;
this.Width = 500;
this.Height = 500;
foreach (Control picB in this.Controls) //遍历窗体中所有PictureBox,并将窗体的PictureBox加入数组中
{
if (picB.GetType() == typeof(PictureBox))
{
pic[i] = (PictureBox)picB;
i++;
}