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 Button[4, 4];
int[] randomize = new int[16];
Random rnd = new Random();
public Form1()
{
InitializeComponent();
}

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

private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 16; i++)
{
randomize[i] = rnd.Next(0, 16);
for (int j = 0; j < i; j++)
{
while (randomize[j] == randomize[i])
{
j = 0;
randomize[i] = rnd.Next(0, 16);
}

}
}

for (int i = 0; i < 4; ++i)
{

for (int j = 0; j < 4; ++j)
{
buttons[i, j].Text = Convert.ToString(randomize[i * 4 + j]);
this.Controls.Add(buttons[i, j]);

}
}


}
}
}1  

arrow
arrow
    全站熱搜

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