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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
Button[,] buttons = new Button[10, 10];
int[] array = new int[10];
public Form1()
{
InitializeComponent();
for (int i = 0; i < 9; i++)
{
array[i] = i;
}
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 50, j * 50);
buttons[i, j].Text = j.ToString();
this.Controls.Add(buttons[i, j]);
buttons[i, j].Click += new EventHandler(button1_Click);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
int d, tmp, k;
Random irand = new Random();
d = irand.Next(1, 10);
label1.Text = d.ToString();
for (int j = 1; j < 10; j++)
{
k = 9 - j + 1;
tmp = array[d];
array[d] = array[k];
array[k] = tmp;
}
label2.Text = array[d].ToString();
}
}
}