2010年11月26日 星期五
2010年11月18日 星期四
2010/11/19 紅綠燈
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
int i,j;
public Form1()
{
InitializeComponent();
i = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
button1.Enabled=false;
button2.Enabled=false;
button3.Enabled = false;
i++;
i = i % 6;
label1.Text = Convert.ToString(i);
j++;
j = j % 6;
switch (j)
{
case 0:
button1.Enabled=true;
break;
case 1:
button2.Enabled=true;
break;
case 2:
button3.Enabled=true;
break;
case 3:
button3.Enabled = true;
break;
case 4:
button3.Enabled = true;
break;
case 5:
button3.Enabled = true;
break;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int i,j;
public Form1()
{
InitializeComponent();
i = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
button1.Enabled=false;
button2.Enabled=false;
button3.Enabled = false;
i++;
i = i % 6;
label1.Text = Convert.ToString(i);
j++;
j = j % 6;
switch (j)
{
case 0:
button1.Enabled=true;
break;
case 1:
button2.Enabled=true;
break;
case 2:
button3.Enabled=true;
break;
case 3:
button3.Enabled = true;
break;
case 4:
button3.Enabled = true;
break;
case 5:
button3.Enabled = true;
break;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
2010/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
{
int i, bno;
int[] arry = new int[9];
public Form1()
{
InitializeComponent();
}
private void button8_Click(object sender, EventArgs e)
{
if (button4.Text == "0")
{
String temp;
temp = button4.Text;
button4.Text = button8.Text;
button8.Text = temp;
}
else if (button9.Text == "0")
{
String temp;
temp = button9.Text;
button9.Text = button8.Text;
button8.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button5_Click_1(object sender, EventArgs e)
{
int rdno;
int temp;
arry[0] = 0;
arry[1] = 1;
arry[2] = 2;
arry[3] = 3;
arry[4] = 4;
arry[5] = 5;
arry[6] = 6;
arry[7] = 7;
arry[8] = 8;
for (int i = 0; i < 9; i++)
{
Random rd = new Random();
rdno = rd.Next(0, 9);
button5.Text = Convert.ToString(rdno);
temp = arry[rdno];
arry[rdno] = arry[arry.Length - (i + 1)];
arry[arry.Length - (i + 1)] = temp;
}
//output
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button6.Text = Convert.ToString(arry[4]);
button7.Text = Convert.ToString(arry[5]);
button8.Text = Convert.ToString(arry[6]);
button9.Text = Convert.ToString(arry[7]);
button10.Text = Convert.ToString(arry[8]);
}
private void button1_Click(object sender, EventArgs e)
{
if (button2.Text == "0")
{
String temp;
temp = button2.Text;
button2.Text = button1.Text;
button1.Text = temp;
}
else if (button4.Text == "0")
{
String temp;
temp = button4.Text;
button4.Text = button1.Text;
button1.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button2_Click(object sender, EventArgs e)
{
if (button1.Text == "0")
{
String temp;
temp = button1.Text;
button1.Text = button2.Text;
button2.Text = temp;
}
else if (button3.Text == "0")
{
String temp;
temp = button3.Text;
button3.Text = button2.Text;
button2.Text = temp;
}
else if (button6.Text == "0")
{
String temp;
temp = button6.Text;
button6.Text = button2.Text;
button2.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button3_Click(object sender, EventArgs e)
{
if (button2.Text == "0")
{
String temp;
temp = button2.Text;
button2.Text = button3.Text;
button3.Text = temp;
}
else if (button7.Text == "0")
{
String temp;
temp = button7.Text;
button7.Text = button3.Text;
button3.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button4_Click(object sender, EventArgs e)
{
if (button1.Text == "0")
{
String temp;
temp = button1.Text;
button1.Text = button4.Text;
button4.Text = temp;
}
else if (button6.Text == "0")
{
String temp;
temp = button6.Text;
button6.Text = button4.Text;
button4.Text = temp;
}
else if (button8.Text == "0")
{
String temp;
temp = button8.Text;
button8.Text = button4.Text;
button4.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button6_Click(object sender, EventArgs e)
{
if (button2.Text == "0")
{
String temp;
temp = button2.Text;
button2.Text = button6.Text;
button6.Text = temp;
}
else if (button4.Text == "0")
{
String temp;
temp = button4.Text;
button4.Text = button6.Text;
button6.Text = temp;
}
else if (button7.Text == "0")
{
String temp;
temp = button7.Text;
button7.Text = button6.Text;
button6.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button7_Click(object sender, EventArgs e)
{
if (button3.Text == "0")
{
String temp;
temp = button3.Text;
button3.Text = button7.Text;
button7.Text = temp;
}
else if (button6.Text == "0")
{
String temp;
temp = button6.Text;
button6.Text = button7.Text;
button7.Text = temp;
}
else if (button10.Text == "0")
{
String temp;
temp = button10.Text;
button10.Text = button7.Text;
button7.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button9_Click(object sender, EventArgs e)
{
if (button6.Text == "0")
{
String temp;
temp = button6.Text;
button6.Text = button9.Text;
button9.Text = temp;
}
else if (button8.Text == "0")
{
String temp;
temp = button8.Text;
button8.Text = button9.Text;
button9.Text = temp;
}
else if (button10.Text == "0")
{
String temp;
temp = button10.Text;
button10.Text = button9.Text;
button9.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button10_Click(object sender, EventArgs e)
{
if (button7.Text == "0")
{
String temp;
temp = button7.Text;
button7.Text = button10.Text;
button10.Text = temp;
}
else if (button9.Text == "0")
{
String temp;
temp = button9.Text;
button9.Text = button10.Text;
button10.Text = temp;
}
else
MessageBox.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
{
int i, bno;
int[] arry = new int[9];
public Form1()
{
InitializeComponent();
}
private void button8_Click(object sender, EventArgs e)
{
if (button4.Text == "0")
{
String temp;
temp = button4.Text;
button4.Text = button8.Text;
button8.Text = temp;
}
else if (button9.Text == "0")
{
String temp;
temp = button9.Text;
button9.Text = button8.Text;
button8.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button5_Click_1(object sender, EventArgs e)
{
int rdno;
int temp;
arry[0] = 0;
arry[1] = 1;
arry[2] = 2;
arry[3] = 3;
arry[4] = 4;
arry[5] = 5;
arry[6] = 6;
arry[7] = 7;
arry[8] = 8;
for (int i = 0; i < 9; i++)
{
Random rd = new Random();
rdno = rd.Next(0, 9);
button5.Text = Convert.ToString(rdno);
temp = arry[rdno];
arry[rdno] = arry[arry.Length - (i + 1)];
arry[arry.Length - (i + 1)] = temp;
}
//output
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button6.Text = Convert.ToString(arry[4]);
button7.Text = Convert.ToString(arry[5]);
button8.Text = Convert.ToString(arry[6]);
button9.Text = Convert.ToString(arry[7]);
button10.Text = Convert.ToString(arry[8]);
}
private void button1_Click(object sender, EventArgs e)
{
if (button2.Text == "0")
{
String temp;
temp = button2.Text;
button2.Text = button1.Text;
button1.Text = temp;
}
else if (button4.Text == "0")
{
String temp;
temp = button4.Text;
button4.Text = button1.Text;
button1.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button2_Click(object sender, EventArgs e)
{
if (button1.Text == "0")
{
String temp;
temp = button1.Text;
button1.Text = button2.Text;
button2.Text = temp;
}
else if (button3.Text == "0")
{
String temp;
temp = button3.Text;
button3.Text = button2.Text;
button2.Text = temp;
}
else if (button6.Text == "0")
{
String temp;
temp = button6.Text;
button6.Text = button2.Text;
button2.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button3_Click(object sender, EventArgs e)
{
if (button2.Text == "0")
{
String temp;
temp = button2.Text;
button2.Text = button3.Text;
button3.Text = temp;
}
else if (button7.Text == "0")
{
String temp;
temp = button7.Text;
button7.Text = button3.Text;
button3.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button4_Click(object sender, EventArgs e)
{
if (button1.Text == "0")
{
String temp;
temp = button1.Text;
button1.Text = button4.Text;
button4.Text = temp;
}
else if (button6.Text == "0")
{
String temp;
temp = button6.Text;
button6.Text = button4.Text;
button4.Text = temp;
}
else if (button8.Text == "0")
{
String temp;
temp = button8.Text;
button8.Text = button4.Text;
button4.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button6_Click(object sender, EventArgs e)
{
if (button2.Text == "0")
{
String temp;
temp = button2.Text;
button2.Text = button6.Text;
button6.Text = temp;
}
else if (button4.Text == "0")
{
String temp;
temp = button4.Text;
button4.Text = button6.Text;
button6.Text = temp;
}
else if (button7.Text == "0")
{
String temp;
temp = button7.Text;
button7.Text = button6.Text;
button6.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button7_Click(object sender, EventArgs e)
{
if (button3.Text == "0")
{
String temp;
temp = button3.Text;
button3.Text = button7.Text;
button7.Text = temp;
}
else if (button6.Text == "0")
{
String temp;
temp = button6.Text;
button6.Text = button7.Text;
button7.Text = temp;
}
else if (button10.Text == "0")
{
String temp;
temp = button10.Text;
button10.Text = button7.Text;
button7.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button9_Click(object sender, EventArgs e)
{
if (button6.Text == "0")
{
String temp;
temp = button6.Text;
button6.Text = button9.Text;
button9.Text = temp;
}
else if (button8.Text == "0")
{
String temp;
temp = button8.Text;
button8.Text = button9.Text;
button9.Text = temp;
}
else if (button10.Text == "0")
{
String temp;
temp = button10.Text;
button10.Text = button9.Text;
button9.Text = temp;
}
else
MessageBox.Show("不能換");
}
private void button10_Click(object sender, EventArgs e)
{
if (button7.Text == "0")
{
String temp;
temp = button7.Text;
button7.Text = button10.Text;
button10.Text = temp;
}
else if (button9.Text == "0")
{
String temp;
temp = button9.Text;
button9.Text = button10.Text;
button10.Text = temp;
}
else
MessageBox.Show("不能換");
}
}
}
訂閱:
文章 (Atom)