課堂上來不及上傳BLOG
複習如下
做一個按鈕button1為控制器
控制讓button2、button3、button4變色
1.宣告 int c ;
2.在button1_click事件中寫
c=c+1; // button1點擊次數每次+1
if (c%3==1) {button2.BackColor=Color.Red
button3.BackColor=Color.Black
button4.BackColor=Color.Black };
else if (c%3==2) {button2.BackColor=Color.Black
button3.BackColor=Color.Tellow
button4.BackColor=Color.Black };
else {button2.BackColor=Color.Black
button3.BackColor=Color.Black
button4.BackColor=Color.Green };
3.新增TIMER後 參數改為TRUE
Click事件可用TIMER控制 程式碼相同
2014年11月28日 星期五
2014年11月27日 星期四
11/28 16個按鈕 亂數未完
做出生成按鈕 還未做隨機變數
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 Button[4, 4]; //宣告按鈕
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
buttons[i, j] = new Button(); //生成4*4按鈕
buttons[i, j].Location = new Point(i * 50, j * 50); //按紐位置為(i*50,j*50)
buttons[i, j].Size = new Size(50, 50); //按鈕大小為50*50
this.Controls.Add(buttons[i, j]);
}
}
}
}
}
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 Button[4, 4]; //宣告按鈕
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
buttons[i, j] = new Button(); //生成4*4按鈕
buttons[i, j].Location = new Point(i * 50, j * 50); //按紐位置為(i*50,j*50)
buttons[i, j].Size = new Size(50, 50); //按鈕大小為50*50
this.Controls.Add(buttons[i, j]);
}
}
}
}
}
2014年11月13日 星期四
11/14 VB作九九乘法表
Private Sub CommandButton1_Click()
Dim i As Integer
For i = 1 To 9
For j = 1 To 9
'列出9*9個格子
Cells(i, j).Value = i * j
'格子值為i*j
Next j
Next i
End Sub
Dim i As Integer
For i = 1 To 9
For j = 1 To 9
'列出9*9個格子
Cells(i, j).Value = i * j
'格子值為i*j
Next j
Next i
End Sub
2014年10月31日 星期五
10/31 井字+判斷輸贏
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{int c=0; //宣告c
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2; //宣告r為c/2的餘數 為了判斷要下X或O
if (r == 1)
{ button1.Text = "O"; } //餘數為1就下O
else
{ button1.Text = "X"; }//餘數為0就下X
button1.Enabled = false;
if ((button1.Text == button2.Text && button2.Text == button3.Text) ||
(button1.Text == button5.Text && button5.Text == button9.Text) ||
(button1.Text == button4.Text && button4.Text == button7.Text))
{ MessageBox.Show("win"); } //如果判斷有三個相同就表示連線 顯示win
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = ""; //先把button變為空白
}
private void button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button2.Text = "O"; }
else
{ button2.Text = "X"; } //在button2下 O或X
button2.Enabled = false;
if ((button2.Text == button1.Text && button1.Text == button3.Text) ||
(button2.Text == button5.Text && button5.Text == button8.Text))
//如果跟button1&3或button5&8 相同
{ MessageBox.Show("win"); } //就顯示win
}
private void button5_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button5.Text = "O"; }
else
{ button5.Text = "X"; }
button5.Enabled = false;
if ((button5.Text == button4.Text && button4.Text == button6.Text) ||
(button5.Text == button2.Text && button2.Text == button8.Text) ||
(button5.Text == button1.Text && button1.Text == button9.Text) ||
(button5.Text == button3.Text && button3.Text == button7.Text))
{ MessageBox.Show("win"); } //判斷方法同button2寫法
}
private void button8_Click(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button7.Text = "O"; }
else
{ button7.Text = "X"; }
button7.Enabled = false;
if ((button7.Text == button1.Text && button1.Text == button4.Text) ||
(button7.Text == button8.Text && button8.Text == button9.Text) ||
(button7.Text == button5.Text && button5.Text == button3.Text))
{ MessageBox.Show("win"); }
}
private void button6_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button6.Text = "O"; }
else
{ button6.Text = "X"; }
button6.Enabled = false;
if ((button3.Text == button2.Text && button2.Text == button1.Text) ||
(button3.Text == button6.Text && button6.Text == button9.Text) ||
(button3.Text == button5.Text && button5.Text == button7.Text))
{ MessageBox.Show("win"); }
}
private void button9_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button4.Text = "O"; }
else
{ button4.Text = "X"; }
button4.Enabled = false;
if ((button4.Text == button5.Text && button5.Text == button6.Text) ||
(button4.Text == button1.Text && button1.Text == button7.Text))
{ MessageBox.Show("win"); }
}
private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button3.Text = "O"; }
else
{ button3.Text = "X"; }
button3.Enabled = false;
if ((button3.Text == button2.Text && button2.Text == button1.Text) ||
(button3.Text == button6.Text && button6.Text == button9.Text) ||
(button3.Text == button5.Text && button5.Text == button7.Text))
{ MessageBox.Show("win"); }
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{int c=0; //宣告c
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2; //宣告r為c/2的餘數 為了判斷要下X或O
if (r == 1)
{ button1.Text = "O"; } //餘數為1就下O
else
{ button1.Text = "X"; }//餘數為0就下X
button1.Enabled = false;
if ((button1.Text == button2.Text && button2.Text == button3.Text) ||
(button1.Text == button5.Text && button5.Text == button9.Text) ||
(button1.Text == button4.Text && button4.Text == button7.Text))
{ MessageBox.Show("win"); } //如果判斷有三個相同就表示連線 顯示win
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = ""; //先把button變為空白
}
private void button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button2.Text = "O"; }
else
{ button2.Text = "X"; } //在button2下 O或X
button2.Enabled = false;
if ((button2.Text == button1.Text && button1.Text == button3.Text) ||
(button2.Text == button5.Text && button5.Text == button8.Text))
//如果跟button1&3或button5&8 相同
{ MessageBox.Show("win"); } //就顯示win
}
private void button5_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button5.Text = "O"; }
else
{ button5.Text = "X"; }
button5.Enabled = false;
if ((button5.Text == button4.Text && button4.Text == button6.Text) ||
(button5.Text == button2.Text && button2.Text == button8.Text) ||
(button5.Text == button1.Text && button1.Text == button9.Text) ||
(button5.Text == button3.Text && button3.Text == button7.Text))
{ MessageBox.Show("win"); } //判斷方法同button2寫法
}
private void button8_Click(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button7.Text = "O"; }
else
{ button7.Text = "X"; }
button7.Enabled = false;
if ((button7.Text == button1.Text && button1.Text == button4.Text) ||
(button7.Text == button8.Text && button8.Text == button9.Text) ||
(button7.Text == button5.Text && button5.Text == button3.Text))
{ MessageBox.Show("win"); }
}
private void button6_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button6.Text = "O"; }
else
{ button6.Text = "X"; }
button6.Enabled = false;
if ((button3.Text == button2.Text && button2.Text == button1.Text) ||
(button3.Text == button6.Text && button6.Text == button9.Text) ||
(button3.Text == button5.Text && button5.Text == button7.Text))
{ MessageBox.Show("win"); }
}
private void button9_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button4.Text = "O"; }
else
{ button4.Text = "X"; }
button4.Enabled = false;
if ((button4.Text == button5.Text && button5.Text == button6.Text) ||
(button4.Text == button1.Text && button1.Text == button7.Text))
{ MessageBox.Show("win"); }
}
private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button3.Text = "O"; }
else
{ button3.Text = "X"; }
button3.Enabled = false;
if ((button3.Text == button2.Text && button2.Text == button1.Text) ||
(button3.Text == button6.Text && button6.Text == button9.Text) ||
(button3.Text == button5.Text && button5.Text == button7.Text))
{ MessageBox.Show("win"); }
}
}
}
方法2:用JUDGE (UNDONE)
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{int c=0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
judge();
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button1.Text = "O"; }
else
{ button1.Text = "X"; } button1.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{ int r;
c = c + 1;
r = c % 2;
if (r==1)
{ button2.Text = "O"; }
else
{ button2.Text = "X"; } button2.Enabled = false;
judge();
}
private void judge()
{
if (button1.Text == "X"&&button2.Text=="X"&&button3.Text=="X"){MessageBox.Show("Win!");}
}
private void button5_Click(object sender, EventArgs e)
{
judge();
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button5.Text = "O"; }
else
{ button5.Text = "X"; } button5.Enabled = false;
}
private void button8_Click(object sender, EventArgs e)
{
judge();
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button8.Text = "O"; }
else
{ button8.Text = "X"; } button8.Enabled = false;
}
private void button7_Click(object sender, EventArgs e)
{
judge();
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button7.Text = "O"; }
else
{ button7.Text = "X"; } button7.Enabled = false;
}
private void button6_Click(object sender, EventArgs e)
{
judge();
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button6.Text = "O"; }
else
{ button6.Text = "X"; } button6.Enabled = false;
}
private void button9_Click(object sender, EventArgs e)
{
judge();
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button9.Text = "O"; }
else
{ button9.Text = "X"; } button9.Enabled = false;
}
private void button4_Click(object sender, EventArgs e)
{
judge();
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button4.Text = "O"; }
else
{ button4.Text = "X"; } button4.Enabled = false;
}
private void button3_Click(object sender, EventArgs e)
{
judge();
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button3.Text = "O"; }
else
{ button3.Text = "X"; } button3.Enabled = false;
}
}
}
2014年10月24日 星期五
10/24 井字遊戲
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 c=0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = ""; //button值設為空白
}
private void button1_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2; //宣告r跟c
if (r==1)
{ button1.Text = "O"; }
else
{ button1.Text = "X"; } button1.Enabled = false; //r用來判斷要填O或X
}
private void button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button2.Text = "O"; }
else
{ button2.Text = "X"; } //r為1就填O r為2填X
button2.Enabled = false; //把按鈕鎖定不能再改
}
private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button3.Text = "O"; }
else
{ button3.Text = "X"; } button3.Enabled = false; //方法同上
}
private void button4_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button4.Text = "O"; }
else
{ button4.Text = "X"; } button4.Enabled = false;
}
private void button5_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button5.Text = "O"; }
else
{ button5.Text = "X"; } button5.Enabled = false;
}
private void button6_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button6.Text = "O"; }
else
{ button6.Text = "X"; } button6.Enabled = false;
}
private void button7_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button7.Text = "O"; }
else
{ button7.Text = "X"; } button7.Enabled = false;
}
private void button8_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button8.Text = "O"; }
else
{ button8.Text = "X"; } button8.Enabled = false;
}
private void button9_Click_1(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button9.Text = "O"; }
else
{ button9.Text = "X"; }
button9.Enabled = false;
}
}
}
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 c=0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = ""; //button值設為空白
}
private void button1_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2; //宣告r跟c
if (r==1)
{ button1.Text = "O"; }
else
{ button1.Text = "X"; } button1.Enabled = false; //r用來判斷要填O或X
}
private void button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button2.Text = "O"; }
else
{ button2.Text = "X"; } //r為1就填O r為2填X
button2.Enabled = false; //把按鈕鎖定不能再改
}
private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button3.Text = "O"; }
else
{ button3.Text = "X"; } button3.Enabled = false; //方法同上
}
private void button4_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button4.Text = "O"; }
else
{ button4.Text = "X"; } button4.Enabled = false;
}
private void button5_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button5.Text = "O"; }
else
{ button5.Text = "X"; } button5.Enabled = false;
}
private void button6_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button6.Text = "O"; }
else
{ button6.Text = "X"; } button6.Enabled = false;
}
private void button7_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button7.Text = "O"; }
else
{ button7.Text = "X"; } button7.Enabled = false;
}
private void button8_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button8.Text = "O"; }
else
{ button8.Text = "X"; } button8.Enabled = false;
}
private void button9_Click_1(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button9.Text = "O"; }
else
{ button9.Text = "X"; }
button9.Enabled = false;
}
}
}
2014年10月23日 星期四
10/24 按鈕賽跑 done
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;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int sum1 = 0;
int sum2 = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) // button1_Click當成骰骰子
{
int d1, d2,dsum;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7); //骰子隨機變數為1~6
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2); //顯示骰子骰到多少
dsum = d1 + d2; //兩顆骰子合計要走幾步
for (int i = 1; i <= dsum; i++)
{
button2.Left = sum1+i; //讓button2移動sum1+i
Thread.Sleep(100); //Delay 0.1秒 移動速度
Application.DoEvents(); //timer的控制項
}
sum1 = sum1 + dsum;
textBox1.Text = Convert.ToString(sum1);
if (button2.Left >= 100) //設100為終點
{ MessageBox.Show("button2 win"); } //到終點則win
}
private void button4_Click(object sender, EventArgs e)
{ //判斷方法同上
int d1, d2, dsum;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
dsum = d1 + d2;
for (int i = 1; i <= dsum; i++)
{
button3.Left = sum2 + i;
Thread.Sleep(100); //Delay 0.1秒
Application.DoEvents();
}
sum2 = sum2 + dsum;
textBox1.Text = Convert.ToString(sum2);
if (button3.Left >= 100)
{ MessageBox.Show("button3 win"); }
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int sum1 = 0;
int sum2 = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) // button1_Click當成骰骰子
{
int d1, d2,dsum;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7); //骰子隨機變數為1~6
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2); //顯示骰子骰到多少
dsum = d1 + d2; //兩顆骰子合計要走幾步
for (int i = 1; i <= dsum; i++)
{
button2.Left = sum1+i; //讓button2移動sum1+i
Thread.Sleep(100); //Delay 0.1秒 移動速度
Application.DoEvents(); //timer的控制項
}
sum1 = sum1 + dsum;
textBox1.Text = Convert.ToString(sum1);
if (button2.Left >= 100) //設100為終點
{ MessageBox.Show("button2 win"); } //到終點則win
}
private void button4_Click(object sender, EventArgs e)
{ //判斷方法同上
int d1, d2, dsum;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
dsum = d1 + d2;
for (int i = 1; i <= dsum; i++)
{
button3.Left = sum2 + i;
Thread.Sleep(100); //Delay 0.1秒
Application.DoEvents();
}
sum2 = sum2 + dsum;
textBox1.Text = Convert.ToString(sum2);
if (button3.Left >= 100)
{ MessageBox.Show("button3 win"); }
}
}
}
2014年10月17日 星期五
10/17 賽跑
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;
using System.Threading; //delay thread
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
int d1, d2;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
for (int i = 1; i <= d1 + d2; i++)
{
button3.Left = 10 * i;
Thread.Sleep(1000); //Delay 1秒
Application.DoEvents();
}
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
for ( int i = ; i <= d1 + d2; i++)
{
button4.Left = 10 * i;
Thread.Sleep(1000); //Delay 1秒
Application.DoEvents();
int a = d1 + d2;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading; //delay thread
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
int d1, d2;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
for (int i = 1; i <= d1 + d2; i++)
{
button3.Left = 10 * i;
Thread.Sleep(1000); //Delay 1秒
Application.DoEvents();
}
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
for ( int i = ; i <= d1 + d2; i++)
{
button4.Left = 10 * i;
Thread.Sleep(1000); //Delay 1秒
Application.DoEvents();
int a = d1 + d2;
}
}
}
}
訂閱:
文章 (Atom)