close

 023.jpg 

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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
Button[,] buttons = new Button[16, 16];
int[] randomize = new int[16];
Random rnd = new Random();

public Form1()
{


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]);

InitializeComponent();
}
}
}

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]);

}
}
}
}
}

arrow
arrow
    全站熱搜

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