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
{
//System.Windows.Forms.Button Button1;
//Button[,] Buttons;
Button[,] buttons = new Button[4, 4];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int x, d1, a1;
int width, height;
int[] my = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
Random irand = new Random();
for (int k = 15; k >= 0; k--)
{
d1 = irand.Next(0, k);
a1 = my[d1];
my[d1] = my[k];
my[k] = a1;
}
for (int j = 0; j < 4; j++)
{
for (int i = 0; i < 4; i++)
{
width = this.Size.Width;
height = this.Size.Height;
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 50, j * 50);
//x = (i + 1) + 4 * j;
x = my[j * 4 + i];
width = 50;
height = 50;
buttons[i, j].Size = new Size(width, height);
buttons[i, j].Text = x.ToString();
this.Controls.Add(buttons[i, j]);
MessageBox.Show("" + x.ToString());
}
}
}
}
}
沒有留言:
張貼留言