close

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

namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
Random rand = new Random();
Button[,] buttons = new Button[4, 4];
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].Size = new Size(80, 80);
buttons[i, j].Location = new Point(i * 85, j * 85);

this.Controls.Add(buttons[i, j]);
}


}
}

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

 

for (int i = 15; i > 1; i--)
{

a = rand.Next(0, i);
b = array[a];
array[a] = array[i];
array[i] = b;
}


for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
x = array[j * 4 + i];

buttons[i, j].Text = Convert.ToString(x);

this.Controls.Add(buttons[i, j]);
}


}
}
}
}

 

arrow
arrow
    全站熱搜

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