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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
int i, j;
int[] randomize = new int[25];
Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
Random rnd = new Random();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (i = 0; i <= 4; i++)
{
for (j = 0; j <= 4; 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)
{
for (int i = 0; i < 25; i++)
{
randomize[i] = rnd.Next(0, 25);
for (int j = 0; j < i; j++)
{
while (randomize[j] == randomize[i])
{
j = 0;
randomize[i] = rnd.Next(0, 25);
}
}
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
Buttons[i, j].Text = Convert.ToString(randomize[i * 5 + j]);
this.Controls.Add(Buttons[i, j]);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
int pro = 0;
for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
{
pro = (j + i * 4) - 4;
Buttons[i, j].Text = pro.ToString();
}
if (pro == 16) { Buttons[4, 4].Text = ""; }
}
}
}
}