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
{
Button[,] buttons = new Button[10, 10];
int[] array = new int[10];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Instantiating all the buttons in the array
for (int i = 1; i < 10; i++)
{
array[i] = i;
}
for (int j = 1; j < 10; j++)
{
buttons[1, j] = new Button();
buttons[1, j].Location = new Point(50*j, 50);
buttons[1, j].Text = array[j].ToString();
this.Controls.Add(buttons[1, j]);
}
/*
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 50, j * 50);
buttons[i,j].Text = j.ToString();
this.Controls.Add(buttons[i, j]);
}
}
*/
}
private void button1_Click(object sender, EventArgs e)
{
int d1,tmp,i;
Random irand = new Random();
d1 = irand.Next(1, 10);
label1.Text = d1.ToString();
for (int j = 1; j < 10; j++)
{
i = 9 - j + 1;
tmp = array[d1];
array[d1] = array[i];
array[i] = tmp;
}
//buttons[1, 1].Text = array[1].ToString();
for (int j = 1; j < 10; j++)
{
// buttons[1, j] = new Button();
buttons[1, j].Location = new Point(50 * j, 50);
buttons[1, j].Text = array[j].ToString();
this.Controls.Add(buttons[1, j]);
}
label2.Text= array[d1].ToString();
}
}
}
2014年12月12日 星期五
2014年12月4日 星期四
homework4 (補做)
紅綠燈
public partial class Form1 : Form
{
int c;
int r;
public Form1()
{
InitializeComponent();
c = 0;
}
private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
label1.Text = "r=" + r;
if (r == 0)
{
button1.Location = new Point(50, 50);
button2.BackColor = Color.Black;
}
else
{
button1.Location = new Point(0, 0);
button2.BackColor = Color.Yellow;
}
}
private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
label1.Text = "r=" + r;
if (r == 0)
{
button1.BackColor = Color.Yellow;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
}
else
if (r == 1)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Red;
button3.BackColor = Color.Black;
}
else
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Green;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
label1.Text = "r=" + r;
if (r == 0)
{
button1.BackColor = Color.Yellow;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
}
else
if (r == 1)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Red;
button3.BackColor = Color.Black;
}
else
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Green;
}
}
}
}
大富翁
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
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 = 1; i <= d1 + d2; i++)
{
Thread.Sleep(1000); //Delay 1秒
Application.DoEvents();
button3.Left = 10 * i;
}
}
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++)
{
button4.Left = 10 * i;
Thread.Sleep(1000); //Delay 1秒
Application.DoEvents();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
骰子
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 ssum1 = 0;
int ssum2 = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2,dsum1;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
dsum1 = d1 + d2;
for (int i = 1; i <= dsum1; i++)
{
Thread.Sleep(200); //Delay 1秒
button2.Left = (ssum1+i)*5;
Application.DoEvents();
}
ssum1 = ssum1 + dsum1;
textBox1.Text = Convert.ToString(ssum1);
if (ssum1 >= 80)
{
textBox2.Text = "button1 win";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
int d1, d2, dsum2;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
dsum2 = d1 + d2;
for (int i = 1; i <= dsum2; i++)
{
Thread.Sleep(200); //Delay 1秒
button4.Left = (ssum2 + i) * 5;
Application.DoEvents();
}
ssum2 = ssum2 + dsum2;
textBox1.Text = Convert.ToString(ssum2);
if (ssum2 >= 80)
{
textBox2.Text = "button2 win";
}
}
}
}
井字
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
int c;
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 = "";
}
private void button1_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button1.Text = "O"; }
else
{ button1.Text = "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"); }
}
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;
if ((button2.Text == button1.Text && button1.Text == button3.Text) ||
(button2.Text == button5.Text && button5.Text == button8.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"); }
}
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 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"); }
}
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 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 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;
if ((button8.Text == button2.Text && button2.Text == button5.Text) ||
(button8.Text == button7.Text && button7.Text == button9.Text))
{ MessageBox.Show("win"); }
}
private void button9_Click(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;
if ((button9.Text == button3.Text && button3.Text == button6.Text) ||
(button9.Text == button8.Text && button8.Text == button7.Text) ||
(button9.Text == button5.Text && button5.Text == button1.Text))
{ MessageBox.Show("win"); }
}
}
}
public partial class Form1 : Form
{
int c;
int r;
public Form1()
{
InitializeComponent();
c = 0;
}
private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
label1.Text = "r=" + r;
if (r == 0)
{
button1.Location = new Point(50, 50);
button2.BackColor = Color.Black;
}
else
{
button1.Location = new Point(0, 0);
button2.BackColor = Color.Yellow;
}
}
private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
label1.Text = "r=" + r;
if (r == 0)
{
button1.BackColor = Color.Yellow;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
}
else
if (r == 1)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Red;
button3.BackColor = Color.Black;
}
else
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Green;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
label1.Text = "r=" + r;
if (r == 0)
{
button1.BackColor = Color.Yellow;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
}
else
if (r == 1)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Red;
button3.BackColor = Color.Black;
}
else
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Green;
}
}
}
}
大富翁
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
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 = 1; i <= d1 + d2; i++)
{
Thread.Sleep(1000); //Delay 1秒
Application.DoEvents();
button3.Left = 10 * i;
}
}
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++)
{
button4.Left = 10 * i;
Thread.Sleep(1000); //Delay 1秒
Application.DoEvents();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
骰子
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 ssum1 = 0;
int ssum2 = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int d1, d2,dsum1;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
dsum1 = d1 + d2;
for (int i = 1; i <= dsum1; i++)
{
Thread.Sleep(200); //Delay 1秒
button2.Left = (ssum1+i)*5;
Application.DoEvents();
}
ssum1 = ssum1 + dsum1;
textBox1.Text = Convert.ToString(ssum1);
if (ssum1 >= 80)
{
textBox2.Text = "button1 win";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
int d1, d2, dsum2;
Random ran = new Random();
d1 = ran.Next(1, 7);
d2 = ran.Next(1, 7);
label1.Text = Convert.ToString(d1);
label2.Text = Convert.ToString(d2);
dsum2 = d1 + d2;
for (int i = 1; i <= dsum2; i++)
{
Thread.Sleep(200); //Delay 1秒
button4.Left = (ssum2 + i) * 5;
Application.DoEvents();
}
ssum2 = ssum2 + dsum2;
textBox1.Text = Convert.ToString(ssum2);
if (ssum2 >= 80)
{
textBox2.Text = "button2 win";
}
}
}
}
井字
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
int c;
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 = "";
}
private void button1_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button1.Text = "O"; }
else
{ button1.Text = "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"); }
}
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;
if ((button2.Text == button1.Text && button1.Text == button3.Text) ||
(button2.Text == button5.Text && button5.Text == button8.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"); }
}
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 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"); }
}
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 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 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;
if ((button8.Text == button2.Text && button2.Text == button5.Text) ||
(button8.Text == button7.Text && button7.Text == button9.Text))
{ MessageBox.Show("win"); }
}
private void button9_Click(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;
if ((button9.Text == button3.Text && button3.Text == button6.Text) ||
(button9.Text == button8.Text && button8.Text == button7.Text) ||
(button9.Text == button5.Text && button5.Text == button1.Text))
{ MessageBox.Show("win"); }
}
}
}
2014年11月27日 星期四
2014年9月26日 星期五
homework2
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, r;
public Form1()
{
InitializeComponent();
c = 0;
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c%3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if(c%3==2)
{
button3.BackColor = Color.Green;
}
}
private void button1_Click(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if (c % 3 == 2)
{
button3.BackColor = Color.Green;
}
}
private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if (c % 3 == 2)
{
button3.BackColor = Color.Green;
}
}
private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if (c % 3 == 2)
{
button3.BackColor = Color.Green;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if (c % 3 == 2)
{
button3.BackColor = Color.Green;
}
}
}
}
這是做顏色變換的程式碼,用一個按鈕來操控,點擊後就可以開始讓幾個方塊規律的變換顏色 !!
這可以用在遊戲畫面登入的色變換,也可以用在遊戲主畫面的轉變!
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, r;
public Form1()
{
InitializeComponent();
c = 0;
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c%3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if(c%3==2)
{
button3.BackColor = Color.Green;
}
}
private void button1_Click(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if (c % 3 == 2)
{
button3.BackColor = Color.Green;
}
}
private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if (c % 3 == 2)
{
button3.BackColor = Color.Green;
}
}
private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if (c % 3 == 2)
{
button3.BackColor = Color.Green;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
if (c % 3 == 0)
{
button1.BackColor = Color.Red;
}
else if (c % 3 == 1)
{
button2.BackColor = Color.Blue;
}
else if (c % 3 == 2)
{
button3.BackColor = Color.Green;
}
}
}
}
這是做顏色變換的程式碼,用一個按鈕來操控,點擊後就可以開始讓幾個方塊規律的變換顏色 !!
這可以用在遊戲畫面登入的色變換,也可以用在遊戲主畫面的轉變!
2014年9月19日 星期五
訂閱:
文章 (Atom)





