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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
int i, j;
Random rnd = new Random();

public Form1()
{
InitializeComponent();
}

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

private void button1_Click(object sender, EventArgs e)
{
int product,k=0;
product = 0;
int[] A=new int[16];
for (int i = 0; i < 16; i++)
{

A[i] = rnd.Next(0, 16);

for (int j = 0; j < i; j++)
{
while (A[j] == A[i])
{
j = 0;
A[i] = rnd.Next(0, 16);
}
}
}
for (i = 1; i <= 4; i++)
{
for (j = 1; j <= 4; j++)
{

//product++;
Buttons[i, j].Text = A[k++].ToString();
}
}
}
}
}

 

arrow
arrow
    全站熱搜

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