close

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
{
Buttons[i, j] = new Button();
Buttons[i, j].Size = new Size(50, 50);
Buttons[i, j].Location = new Point(i * 50, j * 50);
this.Controls.Add(Buttons[i, j]);
}
}



}

private void button1_Click(object sender, EventArgs e)
{
Random r = new Random();
int[] a = {0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

for (int i = 0; i < 15; i++)
{
int j = r.Next(16);
int t = a[j];
a[j] = a[i];
a[i] = t;
}

Buttons[1, 1].Text = a[0].ToString();
Buttons[2, 1].Text = a[1].ToString();
Buttons[3, 1].Text = a[2].ToString();
Buttons[4, 1].Text = a[3].ToString();
Buttons[1, 2].Text = a[4].ToString();
Buttons[2, 2].Text = a[5].ToString();
Buttons[3, 2].Text = a[6].ToString();
Buttons[4, 2].Text = a[7].ToString();
Buttons[1, 3].Text = a[8].ToString();
Buttons[2, 3].Text = a[9].ToString();
Buttons[3, 3].Text = a[10].ToString();
Buttons[4, 3].Text = a[11].ToString();
Buttons[1, 4].Text = a[12].ToString();
Buttons[2, 4].Text = a[13].ToString();
Buttons[3, 4].Text = a[14].ToString();
Buttons[4, 4].Text = a[15].ToString();
for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
{
if (Buttons[i, j].Text == "0")
{
Buttons[i, j].Text = " ";
}
}
}

}
}
}

 

12066029_1017356251619911_8552534143686929054_n  

全站熱搜
創作者介紹
創作者 zxcv7882988 的頭像
zxcv7882988

zxcv7882988的部落格

zxcv7882988 發表在 痞客邦 留言(0) 人氣()