2010年11月26日 星期五
2010年11月18日 星期四
紅綠燈
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;
j = 0;
}
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 % 5;
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;
}
}
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;
j = 0;
}
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 % 5;
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;
}
}
}
}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[] arry = new int[9];
public Form1()
{
InitializeComponent();
}
private void button10_Click(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);
button10.Text = Convert.ToString(rdno);
temp = arry[rdno];
arry[rdno] = arry[arry.Length - (i + 1)];
arry[arry.Length - (i + 1)] = temp;
}
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button5.Text = Convert.ToString(arry[4]);
button6.Text = Convert.ToString(arry[5]);
button7.Text = Convert.ToString(arry[6]);
button8.Text = Convert.ToString(arry[7]);
button9.Text = Convert.ToString(arry[8]);
}
private void Form1_Load(object sender, EventArgs e)
{
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;
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button5.Text = Convert.ToString(arry[4]);
button6.Text = Convert.ToString(arry[5]);
button7.Text = Convert.ToString(arry[6]);
button8.Text = Convert.ToString(arry[7]);
button9.Text = Convert.ToString(arry[8]);
}
}
}
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[] arry = new int[9];
public Form1()
{
InitializeComponent();
}
private void button10_Click(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);
button10.Text = Convert.ToString(rdno);
temp = arry[rdno];
arry[rdno] = arry[arry.Length - (i + 1)];
arry[arry.Length - (i + 1)] = temp;
}
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button5.Text = Convert.ToString(arry[4]);
button6.Text = Convert.ToString(arry[5]);
button7.Text = Convert.ToString(arry[6]);
button8.Text = Convert.ToString(arry[7]);
button9.Text = Convert.ToString(arry[8]);
}
private void Form1_Load(object sender, EventArgs e)
{
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;
button1.Text = Convert.ToString(arry[0]);
button2.Text = Convert.ToString(arry[1]);
button3.Text = Convert.ToString(arry[2]);
button4.Text = Convert.ToString(arry[3]);
button5.Text = Convert.ToString(arry[4]);
button6.Text = Convert.ToString(arry[5]);
button7.Text = Convert.ToString(arry[6]);
button8.Text = Convert.ToString(arry[7]);
button9.Text = Convert.ToString(arry[8]);
}
}
}
訂閱:
文章 (Atom)