2010年11月26日 星期五
2010年11月12日 星期五
11/12 亂數
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
{
Form2 newform = new Form2();
System.Windows.Forms.Button[] Buttons;
int bno;
int[] a = new int[9];
int temp;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
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 + 100);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i=0;i<9;i++)
{
a[i] = i;
}
for (int i = 0; i < 9; i++)
{
Random rd = new Random();
bno = rd.Next(0, 9);
temp = a[bno];
a[bno] = a[a.Length - (i + 1)];
a[a.Length - (i + 1)] = temp;
}
for (int i = 0; i < 9; i++)
{
Buttons[i].Text = Convert.ToString(a[i]);
}
}
private void button2_Click(object sender, EventArgs e)
{
newform.Show();
}
}
}
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
{
Form2 newform = new Form2();
System.Windows.Forms.Button[] Buttons;
int bno;
int[] a = new int[9];
int temp;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
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 + 100);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i=0;i<9;i++)
{
a[i] = i;
}
for (int i = 0; i < 9; i++)
{
Random rd = new Random();
bno = rd.Next(0, 9);
temp = a[bno];
a[bno] = a[a.Length - (i + 1)];
a[a.Length - (i + 1)] = temp;
}
for (int i = 0; i < 9; i++)
{
Buttons[i].Text = Convert.ToString(a[i]);
}
}
private void button2_Click(object sender, EventArgs e)
{
newform.Show();
}
}
}
訂閱:
文章 (Atom)