rd.Next(0,8);
/*
參考
rd.NextDouble();
rd.Next(1);
rd.Next();
*/
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;
System.Windows.Forms.Button[] Buttons;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Button1 = new System.Windows.Forms.Button();
// this.Controls.Add(Button1);
int[] score = new int[9];
Buttons = new System.Windows.Forms.Button[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
this.Controls.Add(Buttons[i]);
if (i <= 2)
Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 10);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70);
//score[i]=rd.Next(0, 8);
score[i] = i;
}
int temp = 0;
int rdno = 0;
Random rd = new Random();
// 不重覆的亂數
for (int i = 8; i >= 0; --i)
{
rdno = rd.Next(0, i);
temp = score[rdno];
score[rdno] = score[i];
score[i] = temp;
}
for (int i = 0; i < 9; ++i)
{
Buttons[i].Text = Convert.ToString(score[i]);
}
}
}
}
沒有留言:
張貼留言