2015年10月30日 星期五
陣列按鈕
基本陣列按鈕
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
int r = 0, r6 = 0;
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();
Buttons[i, j].Size = new Size(50, 50);
Buttons[i, j].Location = new Point(i * 50, j * 50);
this.Controls.Add(Buttons[i, j]);//出現在畫面中
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Random r2 = new Random();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
r6 = i + j * 4;
r = r2.Next(0, 15);
Buttons[i, j].Text = r6.ToString();
}
}
}
}
}
產生隨機亂數陣列按鈕
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
int r = 0, r6 = 0;
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();
Buttons[i, j].Size = new Size(50, 50);
Buttons[i, j].Location = new Point(i * 50, j * 50);
this.Controls.Add(Buttons[i, j]);//出現在畫面中
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Random r2 = new Random();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
r6 = i + j * 4;
r = r2.Next(0, 15);
Buttons[i, j].Text = r.ToString();
}
}
}
}
}
2015年10月23日 星期五
推盤
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int r1 = 0;
int r2 = 0;
int r3 = 0;
int r4 = 0;
int r5 = 0;
int r6 = 0;
int r7 = 0;
int r8 = 0;
int r9 = 0;
public Form1()
{
InitializeComponent();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
}
private void button10_Click(object sender, EventArgs e)
{
Random rnd = new Random();
int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
for (int i = 0; i < 9; ++i)
{
int j = rnd.Next(8);
int t = a[j];
a[j] = a[i];
a[i] = t;
}
button1.Text = a[0].ToString();
button2.Text = a[1].ToString();
button3.Text = a[2].ToString();
button4.Text = a[3].ToString();
button5.Text = a[4].ToString();
button6.Text = a[5].ToString();
button7.Text = a[6].ToString();
button8.Text = a[7].ToString();
button9.Text = a[8].ToString();
//button10.Enabled = false;
}
}
}
2015年10月22日 星期四
拉霸
程式設計工藝大師
public partial class Form1 : Form
{
int c1 = 0, d1 = 0,c2=0,d2=0,c3=0,d3=0;
int r1 = 100, r2 = 100, r3 = 100;
int money=0,moneyget=0;
string a = "win";
string b = "lose";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
c1=c1+1;
d1 = c1 % 10;
button1.Text = d1.ToString();
if (c1 >= r1) timer1.Enabled = false;
}
private void timer2_Tick(object sender, EventArgs e)
{
c2 = c2 + 1;
d2 = c2 % 10;
button2.Text =d2.ToString();
if (c2 >= r2) timer2.Enabled = false;
}
private void timer3_Tick(object sender, EventArgs e)
{
c3 = c3 + 1;
d3 = c3 % 10;
button3.Text = d3.ToString();
if (c3 >= r3)
timer3.Enabled = false;
if (d1 == 0 && d2 == 0 && d3 == 0)
{
button6.Text = a.ToString();
}
if (d1 == 1 && d2 == 1 && d3 == 1)
{
button6.Text = a.ToString();
}
if (d1 == 2 && d2 == 2 && d3 == 2)
{
button6.Text = a.ToString();
}
else if (d1 == 3 && d2 == 3 && d3 == 3)
{
button6.Text = a.ToString();
}
if (d1 == 4 && d2 == 4 && d3 == 4)
{
button6.Text = a.ToString();
}
if (d1 == 5 && d2 == 5 && d3 == 5)
{
button6.Text = a.ToString();
}
if (d1 == 6 && d2 == 6 && d3 == 6)
{
button6.Text = a.ToString();
}
if (d1 == 7 && d2 == 7 && d3 == 7)
{
button6.Text = a.ToString();
}
if (d1 == 8 && d2 == 8 && d3 == 8)
{
button6.Text = a.ToString();
}
if (d1 == 9 && d2 == 9 && d3 == 9)
{
button6.Text = a.ToString();
}
if (d1 != d2 || d2 != d3 || d1 != d3)
{
button6.Text = b.ToString();
}
}
private void button4_Click(object sender, EventArgs e)
{
c1 = 0;
c2 = 0;
c3 = 0;
timer1.Enabled = true;
timer2.Enabled = true;
timer3.Enabled = true;
Random rnd = new Random();
r1 = rnd.Next(100, 200);
r2 = rnd.Next(200, 300);
r3 = rnd.Next(300, 400);
}
private void button5_Click(object sender, EventArgs e)
{
money=money+5;
button5.Text = money.ToString();
}
private void button6_Click(object sender, EventArgs e)
{
}
}
}
public partial class Form1 : Form
{
int c1 = 0, d1 = 0,c2=0,d2=0,c3=0,d3=0;
int r1 = 100, r2 = 100, r3 = 100;
int money=0,moneyget=0;
string a = "win";
string b = "lose";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
c1=c1+1;
d1 = c1 % 10;
button1.Text = d1.ToString();
if (c1 >= r1) timer1.Enabled = false;
}
private void timer2_Tick(object sender, EventArgs e)
{
c2 = c2 + 1;
d2 = c2 % 10;
button2.Text =d2.ToString();
if (c2 >= r2) timer2.Enabled = false;
}
private void timer3_Tick(object sender, EventArgs e)
{
c3 = c3 + 1;
d3 = c3 % 10;
button3.Text = d3.ToString();
if (c3 >= r3)
timer3.Enabled = false;
if (d1 == 0 && d2 == 0 && d3 == 0)
{
button6.Text = a.ToString();
}
if (d1 == 1 && d2 == 1 && d3 == 1)
{
button6.Text = a.ToString();
}
if (d1 == 2 && d2 == 2 && d3 == 2)
{
button6.Text = a.ToString();
}
else if (d1 == 3 && d2 == 3 && d3 == 3)
{
button6.Text = a.ToString();
}
if (d1 == 4 && d2 == 4 && d3 == 4)
{
button6.Text = a.ToString();
}
if (d1 == 5 && d2 == 5 && d3 == 5)
{
button6.Text = a.ToString();
}
if (d1 == 6 && d2 == 6 && d3 == 6)
{
button6.Text = a.ToString();
}
if (d1 == 7 && d2 == 7 && d3 == 7)
{
button6.Text = a.ToString();
}
if (d1 == 8 && d2 == 8 && d3 == 8)
{
button6.Text = a.ToString();
}
if (d1 == 9 && d2 == 9 && d3 == 9)
{
button6.Text = a.ToString();
}
if (d1 != d2 || d2 != d3 || d1 != d3)
{
button6.Text = b.ToString();
}
}
private void button4_Click(object sender, EventArgs e)
{
c1 = 0;
c2 = 0;
c3 = 0;
timer1.Enabled = true;
timer2.Enabled = true;
timer3.Enabled = true;
Random rnd = new Random();
r1 = rnd.Next(100, 200);
r2 = rnd.Next(200, 300);
r3 = rnd.Next(300, 400);
}
private void button5_Click(object sender, EventArgs e)
{
money=money+5;
button5.Text = money.ToString();
}
private void button6_Click(object sender, EventArgs e)
{
}
}
}
2015年10月2日 星期五
紅綠燈語法
程式設計工藝大師
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int c = 0, d = 0;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
d = c % 3;
if (d == 2)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Red;
}
else if (d == 1)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.Black;
}
else
{
button1.BackColor = Color.Green;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
}
}
private void bindingSource1_CurrentChanged(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.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int c = 0, d = 0;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
d = c % 3;
if (d == 2)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Red;
}
else if (d == 1)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.Black;
}
else
{
button1.BackColor = Color.Green;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
}
}
private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
}
}
}
訂閱:
文章 (Atom)