2010年11月26日 星期五
2010年11月25日 星期四
2010年11月12日 星期五
99/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;
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
{
public string str = ""; //此字串用於存取使用者點擊的數字鍵
public double all = 0;//用於計算結果暫存變數
public int how = 0;//用於判斷使用者按下的運算元
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "2";
textBox1.Text = str;
}
private void button1_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "0";
textBox1.Text = str;
}
private void button2_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//若字串內容只有,則可視為沒有內容
str += "1"; //字串內容+"1"
textBox1.Text = str;//顯示字串內容
}
private void button4_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "3";
textBox1.Text = str;
}
private void button5_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "4";
textBox1.Text = str;
}
private void button6_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "5";
textBox1.Text = str;
}
private void button7_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "6";
textBox1.Text = str;
}
private void button8_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "7";
textBox1.Text = str;
}
private void button9_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "8";
textBox1.Text = str;
}
private void button10_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "9";
textBox1.Text = str;
}
private void button16_Click(object sender, EventArgs e)
{
str = ""; //讓變數都初始化
textBox1.Text = "0";
}
private void button11_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };all += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };all -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };all *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };all /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } all = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(all);
how = 1;
label1.Text = " +";
str = "";
}
private void button15_Click(object sender, EventArgs e)
{
if (str != "")//點擊=鍵還需判斷使用者是否輸入了數字內容
{ //how用於判斷使用者按壓了哪一個運算字元.1:+ 2:- 3:* 4:/ 0:=,代表歸零
//先執行上一步使用者所選擇的運算元
if (how == 1) { all += Convert.ToDouble(str); }
else if (how == 2) { all -= Convert.ToDouble(str); }
else if (how == 3) { all *= Convert.ToDouble(str); }
else if (how == 4) { all /= Convert.ToDouble(str); }
else if (all == 0) { all = Convert.ToDouble(str); }
else all = Convert.ToDouble(str);
}
how = 0;//再儲存使用者所按下的運算元
label1.Text = "=";
str = Convert.ToString(all);
textBox1.Text = str;
}
private void button12_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };all += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };all -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };all *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };all /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } all = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(all);
how = 2;
label1.Text = " -";
str = "";
}
private void button13_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };all += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };all -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };all *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };all /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } all = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(all);
how = 3;
label1.Text = " *";
str = "";
}
private void button14_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };all += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };all -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };all *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };all /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } all = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(all);
how = 4;
label1.Text = " /";
str = "";
}
}
}
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;
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
{
public string str = ""; //此字串用於存取使用者點擊的數字鍵
public double all = 0;//用於計算結果暫存變數
public int how = 0;//用於判斷使用者按下的運算元
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "2";
textBox1.Text = str;
}
private void button1_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "0";
textBox1.Text = str;
}
private void button2_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }//若字串內容只有,則可視為沒有內容
str += "1"; //字串內容+"1"
textBox1.Text = str;//顯示字串內容
}
private void button4_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "3";
textBox1.Text = str;
}
private void button5_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "4";
textBox1.Text = str;
}
private void button6_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "5";
textBox1.Text = str;
}
private void button7_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "6";
textBox1.Text = str;
}
private void button8_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "7";
textBox1.Text = str;
}
private void button9_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "8";
textBox1.Text = str;
}
private void button10_Click(object sender, EventArgs e)
{
if (str == "0") { str = ""; }
str += "9";
textBox1.Text = str;
}
private void button16_Click(object sender, EventArgs e)
{
str = ""; //讓變數都初始化
textBox1.Text = "0";
}
private void button11_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };all += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };all -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };all *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };all /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } all = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(all);
how = 1;
label1.Text = " +";
str = "";
}
private void button15_Click(object sender, EventArgs e)
{
if (str != "")//點擊=鍵還需判斷使用者是否輸入了數字內容
{ //how用於判斷使用者按壓了哪一個運算字元.1:+ 2:- 3:* 4:/ 0:=,代表歸零
//先執行上一步使用者所選擇的運算元
if (how == 1) { all += Convert.ToDouble(str); }
else if (how == 2) { all -= Convert.ToDouble(str); }
else if (how == 3) { all *= Convert.ToDouble(str); }
else if (how == 4) { all /= Convert.ToDouble(str); }
else if (all == 0) { all = Convert.ToDouble(str); }
else all = Convert.ToDouble(str);
}
how = 0;//再儲存使用者所按下的運算元
label1.Text = "=";
str = Convert.ToString(all);
textBox1.Text = str;
}
private void button12_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };all += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };all -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };all *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };all /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } all = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(all);
how = 2;
label1.Text = " -";
str = "";
}
private void button13_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };all += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };all -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };all *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };all /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } all = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(all);
how = 3;
label1.Text = " *";
str = "";
}
private void button14_Click(object sender, EventArgs e)
{
if (how == 1)
{ if (str == "") { str = "0"; };all += Convert.ToDouble(str); }
else if (how == 2)
{ if (str == "") { str = "0"; };all -= Convert.ToDouble(str); }
else if (how == 3)
{ if (str == "") { str = "1"; };all *= Convert.ToDouble(str); }
else if (how == 4)
{ if (str == "") { str = "1"; };all /= Convert.ToDouble(str); }
else if (how == 0)
{ if (str == "") { str = "0"; } all = Convert.ToDouble(str); }
textBox1.Text = Convert.ToString(all);
how = 4;
label1.Text = " /";
str = "";
}
}
}
2010年11月11日 星期四
99/11/12 期中考...
小算盤(按鈕要自己拉)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
double num1 = 0.0, num2 = 0.0; // 運算元
string op; // 運算子
bool reinput = true;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
inputNumber(this.button1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
inputNumber(this.button2.Text);
}
private void button3_Click(object sender, EventArgs e)
{
inputNumber(this.button3.Text);
}
private void button4_Click(object sender, EventArgs e)
{
inputNumber(this.button4.Text);
}
private void button5_Click(object sender, EventArgs e)
{
inputNumber(this.button5.Text);
}
private void button6_Click(object sender, EventArgs e)
{
inputNumber(this.button6.Text);
}
private void button7_Click(object sender, EventArgs e)
{
inputNumber(this.button7.Text);
}
private void button8_Click(object sender, EventArgs e)
{
inputNumber(this.button8.Text);
}
private void button9_Click(object sender, EventArgs e)
{
inputNumber(this.button9.Text);
}
private void button10_Click(object sender, EventArgs e)
{
inputNumber(this.button10.Text);
}
private void button11_Click(object sender, EventArgs e)
{
inputOP(this.button11.Text);
}
private void button12_Click(object sender, EventArgs e)
{
inputOP(this.button12.Text);
}
private void button13_Click(object sender, EventArgs e)
{
inputOP(this.button13.Text);
}
private void button14_Click(object sender, EventArgs e)
{
inputOP(this.button14.Text);
}
private void button15_Click(object sender, EventArgs e)
{
inputOP(this.button15.Text);
}
private void button16_Click(object sender, EventArgs e)
{
this.textBox1.Text = "0";
reinput = true;
}
private void button17_Click(object sender, EventArgs e)
{
num2 = Convert.ToDouble(this.textBox1.Text);
if (op == "+")
this.textBox1.Text = Convert.ToString(num1 + num2);
else if (op == "-")
this.textBox1.Text = Convert.ToString(num1 - num2);
else if (op == "*")
this.textBox1.Text = Convert.ToString(num1 * num2);
else if (op == "/")
{
if (num2 == 0) this.textBox1.Text = "除數不得為零!";
else this.textBox1.Text = Convert.ToString(num1 / num2);
}
else if (op == "%")
{
if (num2 == 0) this.textBox1.Text = "除數不得為零!";
else this.textBox1.Text = Convert.ToString(num1 % num2);
}
op = "";
reinput = true;
}
private void button18_Click(object sender, EventArgs e)
{
Int64 result;
if (Int64.TryParse(this.textBox1.Text, out result))
inputNumber(this.button18.Text);
}
private void button19_Click(object sender, EventArgs e)
{
this.textBox1.Text = Convert.ToString(0 - Convert.ToDouble(this.textBox1.Text));
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
this.button18.Visible = false;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
this.button18.Visible = true;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
this.button19.Visible = !this.button19.Visible;
}
private void inputNumber(string btText)
{
if ((this.textBox1.Text.Length == 1 && this.textBox1.Text == "0") || reinput == true)
{
if (btText != ".")
this.textBox1.Text = btText;
else
this.textBox1.Text = this.textBox1.Text + btText;
reinput = false;
}
else
this.textBox1.Text = this.textBox1.Text + btText;
}
private void inputOP(string btText)
{
op = btText;
num1 = Convert.ToDouble(this.textBox1.Text);
reinput = true;
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
}
}
-------------------------------------------------------------------------------------------------------------
OX
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
int OX = 0;
int[,] victory = new int[3, 3];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.button1_Click(sender, e);
}
private void button1_Click(object sender, EventArgs e)
{
OX = 0;
for (int x = 0; x < 3; x++)
for (int y = 0; y < 3; y++)
victory[x, y] = -3;
foreach (Control ctrl in this.Controls)
{
if (ctrl is PictureBox)
{
PictureBox p = (PictureBox)ctrl;
p.Image = null;
}
}
this.label1.Text = "";
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox1, 0, 0);
}
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox2, 0, 1);
}
private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox3, 0, 2);
}
private void pictureBox4_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox4, 1, 0);
}
private void pictureBox5_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox5, 1, 1);
}
private void pictureBox6_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox6, 1, 2);
}
private void pictureBox7_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox7, 2, 0);
}
private void pictureBox8_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox8, 2, 1);
}
private void pictureBox9_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox9, 2, 2);
}
private void drawOX(PictureBox p, int x, int y)
{
if (p.Image == null && this.label1.Text == "")
{
OX = ++OX % 2;
victory[x, y] = OX;
if (OX == 1)
p.Image = System.Drawing.Image.FromFile("..\\..\\pic\\O.jpg");
else
p.Image = System.Drawing.Image.FromFile("..\\..\\pic\\X.jpg");
this.label1.Text = check_victory();
}
}
private string check_victory()
{
for (int x = 0; x < 3; x++) // 橫向檢查
{
int sum = 0;
for (int y = 0; y < 3; y++)
sum += victory[x, y];
if (sum == 0) return "X獲勝!";
else if (sum == 3) return "O獲勝!";
}
for (int y = 0; y < 3; y++) // 縱向檢查
{
int sum = 0;
for (int x = 0; x < 3; x++)
sum += victory[x, y];
if (sum == 0) return "X獲勝!";
else if (sum == 3) return "O獲勝!";
}
if (victory[0, 0] + victory[1, 1] + victory[2, 2] == 0) // 對角線檢查
return "X獲勝!";
else if (victory[0, 0] + victory[1, 1] + victory[2, 2] == 3)
return "O獲勝!";
if (victory[0, 2] + victory[1, 1] + victory[2, 0] == 0) // 對角線檢查
return "X獲勝!";
else if (victory[0, 2] + victory[1, 1] + victory[2, 0] == 3)
return "O獲勝!";
return "";
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
double num1 = 0.0, num2 = 0.0; // 運算元
string op; // 運算子
bool reinput = true;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
inputNumber(this.button1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
inputNumber(this.button2.Text);
}
private void button3_Click(object sender, EventArgs e)
{
inputNumber(this.button3.Text);
}
private void button4_Click(object sender, EventArgs e)
{
inputNumber(this.button4.Text);
}
private void button5_Click(object sender, EventArgs e)
{
inputNumber(this.button5.Text);
}
private void button6_Click(object sender, EventArgs e)
{
inputNumber(this.button6.Text);
}
private void button7_Click(object sender, EventArgs e)
{
inputNumber(this.button7.Text);
}
private void button8_Click(object sender, EventArgs e)
{
inputNumber(this.button8.Text);
}
private void button9_Click(object sender, EventArgs e)
{
inputNumber(this.button9.Text);
}
private void button10_Click(object sender, EventArgs e)
{
inputNumber(this.button10.Text);
}
private void button11_Click(object sender, EventArgs e)
{
inputOP(this.button11.Text);
}
private void button12_Click(object sender, EventArgs e)
{
inputOP(this.button12.Text);
}
private void button13_Click(object sender, EventArgs e)
{
inputOP(this.button13.Text);
}
private void button14_Click(object sender, EventArgs e)
{
inputOP(this.button14.Text);
}
private void button15_Click(object sender, EventArgs e)
{
inputOP(this.button15.Text);
}
private void button16_Click(object sender, EventArgs e)
{
this.textBox1.Text = "0";
reinput = true;
}
private void button17_Click(object sender, EventArgs e)
{
num2 = Convert.ToDouble(this.textBox1.Text);
if (op == "+")
this.textBox1.Text = Convert.ToString(num1 + num2);
else if (op == "-")
this.textBox1.Text = Convert.ToString(num1 - num2);
else if (op == "*")
this.textBox1.Text = Convert.ToString(num1 * num2);
else if (op == "/")
{
if (num2 == 0) this.textBox1.Text = "除數不得為零!";
else this.textBox1.Text = Convert.ToString(num1 / num2);
}
else if (op == "%")
{
if (num2 == 0) this.textBox1.Text = "除數不得為零!";
else this.textBox1.Text = Convert.ToString(num1 % num2);
}
op = "";
reinput = true;
}
private void button18_Click(object sender, EventArgs e)
{
Int64 result;
if (Int64.TryParse(this.textBox1.Text, out result))
inputNumber(this.button18.Text);
}
private void button19_Click(object sender, EventArgs e)
{
this.textBox1.Text = Convert.ToString(0 - Convert.ToDouble(this.textBox1.Text));
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
this.button18.Visible = false;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
this.button18.Visible = true;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
this.button19.Visible = !this.button19.Visible;
}
private void inputNumber(string btText)
{
if ((this.textBox1.Text.Length == 1 && this.textBox1.Text == "0") || reinput == true)
{
if (btText != ".")
this.textBox1.Text = btText;
else
this.textBox1.Text = this.textBox1.Text + btText;
reinput = false;
}
else
this.textBox1.Text = this.textBox1.Text + btText;
}
private void inputOP(string btText)
{
op = btText;
num1 = Convert.ToDouble(this.textBox1.Text);
reinput = true;
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
}
}
-------------------------------------------------------------------------------------------------------------
OX
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
int OX = 0;
int[,] victory = new int[3, 3];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.button1_Click(sender, e);
}
private void button1_Click(object sender, EventArgs e)
{
OX = 0;
for (int x = 0; x < 3; x++)
for (int y = 0; y < 3; y++)
victory[x, y] = -3;
foreach (Control ctrl in this.Controls)
{
if (ctrl is PictureBox)
{
PictureBox p = (PictureBox)ctrl;
p.Image = null;
}
}
this.label1.Text = "";
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox1, 0, 0);
}
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox2, 0, 1);
}
private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox3, 0, 2);
}
private void pictureBox4_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox4, 1, 0);
}
private void pictureBox5_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox5, 1, 1);
}
private void pictureBox6_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox6, 1, 2);
}
private void pictureBox7_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox7, 2, 0);
}
private void pictureBox8_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox8, 2, 1);
}
private void pictureBox9_MouseDown(object sender, MouseEventArgs e)
{
drawOX(this.pictureBox9, 2, 2);
}
private void drawOX(PictureBox p, int x, int y)
{
if (p.Image == null && this.label1.Text == "")
{
OX = ++OX % 2;
victory[x, y] = OX;
if (OX == 1)
p.Image = System.Drawing.Image.FromFile("..\\..\\pic\\O.jpg");
else
p.Image = System.Drawing.Image.FromFile("..\\..\\pic\\X.jpg");
this.label1.Text = check_victory();
}
}
private string check_victory()
{
for (int x = 0; x < 3; x++) // 橫向檢查
{
int sum = 0;
for (int y = 0; y < 3; y++)
sum += victory[x, y];
if (sum == 0) return "X獲勝!";
else if (sum == 3) return "O獲勝!";
}
for (int y = 0; y < 3; y++) // 縱向檢查
{
int sum = 0;
for (int x = 0; x < 3; x++)
sum += victory[x, y];
if (sum == 0) return "X獲勝!";
else if (sum == 3) return "O獲勝!";
}
if (victory[0, 0] + victory[1, 1] + victory[2, 2] == 0) // 對角線檢查
return "X獲勝!";
else if (victory[0, 0] + victory[1, 1] + victory[2, 2] == 3)
return "O獲勝!";
if (victory[0, 2] + victory[1, 1] + victory[2, 0] == 0) // 對角線檢查
return "X獲勝!";
else if (victory[0, 2] + victory[1, 1] + victory[2, 0] == 3)
return "O獲勝!";
return "";
}
}
}
2010年11月6日 星期六
試試小算盤
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
{
System.Windows.Forms.TextBox[] textBoxes;
System.Windows.Forms.Button[] Buttons;
int i=1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBoxes = new System.Windows.Forms.TextBox[16];
textBoxes[i] = new TextBox();
this.Controls.Add(textBoxes[i]);
textBoxes[i].Location = new System.Drawing.Point(i * 10, 10);
textBoxes[i].Size = new Size(260, 22);
Buttons = new System.Windows.Forms.Button[16];
for (int j = 0; j < 16; j++)
{
Buttons[j] = new Button();
this.Controls.Add(Buttons[j]);
if (j <= 3)
Buttons[j].Location = new System.Drawing.Point(10 + j * 65, 50);
else if (j > 3 && j <= 7)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 4) * 65, 80);
else if (j > 7 && j <= 11)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 8) * 65, 110);
else if (j > 11 && j <= 15)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 12) * 65, 140);
Buttons[j].Size = new Size(60, 23);
}
for (int j = 0; j < 10; j++)
{
Buttons[j].Text = "" + j + "";
}
for (int j = 10; j < 11; j++)
{ Buttons[j].Text = ".";
}
for (int j = 11; j < 12; j++)
{ Buttons[j].Text = "=";
}
for (int j = 12; j < 13; j++)
{
Buttons[j].Text = "+";
}
for (int j = 13; j < 14; j++)
{
Buttons[j].Text = "-";
}
for (int j = 14; j < 15; j++)
{
Buttons[j].Text = "*";
}
for (int j = 15; j < 16; j++)
{
Buttons[j].Text = "/";
}
}
}
}
-------------------------------------------------------------------------------------------------------------
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
{
System.Windows.Forms.TextBox[] textBoxes;
System.Windows.Forms.Button[] Buttons;
int i = 1, bno,j;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBoxes = new System.Windows.Forms.TextBox[16];
textBoxes[i] = new TextBox();
this.Controls.Add(textBoxes[i]);
textBoxes[i].Location = new System.Drawing.Point(i * 10, 10);
textBoxes[i].Size = new Size(260, 22);
Buttons = new System.Windows.Forms.Button[16];
for (int j = 0; j < 16; j++)
{
Buttons[j] = new Button();
this.Controls.Add(Buttons[j]);
if (j <= 3)
Buttons[j].Location = new System.Drawing.Point(10 + j * 65, 50);
else if (j > 3 && j <= 7)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 4) * 65, 80);
else if (j > 7 && j <= 11)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 8) * 65, 110);
else if (j > 11 && j <= 15)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 12) * 65, 140);
Buttons[j].Size = new Size(60, 23);
}
for (int j = 0; j < 10; j++)
{
Buttons[j].Text = "" + j + "";
}
for (int j = 10; j < 11; j++)
{
Buttons[j].Text = ".";
}
for (int j = 11; j < 12; j++)
{
Buttons[j].Text = "=";
}
for (int j = 12; j < 13; j++)
{
Buttons[j].Text = "+";
}
for (int j = 13; j < 14; j++)
{
Buttons[j].Text = "-";
}
for (int j = 14; j < 15; j++)
{
Buttons[j].Text = "*";
}
for (int j = 15; j < 16; j++)
{
Buttons[j].Text = "/";
}
}
public void Buttons_Click(object sender, EventArgs e)
{
for (int j = 0; j < 10; ++j)
{
Buttons[j].Text = Convert.ToString( j );
for (int i = 1; i < 2; ++i)
{
j = Convert.ToInt16(textBoxes[i].Text);
textBoxes[i].Text=""+j;
}
}
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
/*String tnum = sender.ToString();
int tlen = tnum.Length;
String no = tnum.Substring(tlen);
for (int j = 0; j < 16; j++)
{
if (Buttons[j].Text == no)
bno = j;
}
switch (bno)
{
case 0:
MessageBox.Show("0");
break;
case 1:
MessageBox.Show("1");
break;
case 2:
MessageBox.Show("2");
break;
case 3:
MessageBox.Show("3");
break;
case 4:
MessageBox.Show("4");
break;
case 5:
MessageBox.Show("5");
break;
case 6:
MessageBox.Show("6");
break;
case 7:
MessageBox.Show("7");
break;
case 8:
MessageBox.Show("8");
break;
case 9:
MessageBox.Show("9");
break;
case 10:
MessageBox.Show("10");
break;
case 11:
MessageBox.Show("11");
break;
case 12:
MessageBox.Show("12");
break;
case 13:
MessageBox.Show("13");
break;
case 14:
MessageBox.Show("14");
break;
case 15:
MessageBox.Show("15");
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
System.Windows.Forms.TextBox[] textBoxes;
System.Windows.Forms.Button[] Buttons;
int i=1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBoxes = new System.Windows.Forms.TextBox[16];
textBoxes[i] = new TextBox();
this.Controls.Add(textBoxes[i]);
textBoxes[i].Location = new System.Drawing.Point(i * 10, 10);
textBoxes[i].Size = new Size(260, 22);
Buttons = new System.Windows.Forms.Button[16];
for (int j = 0; j < 16; j++)
{
Buttons[j] = new Button();
this.Controls.Add(Buttons[j]);
if (j <= 3)
Buttons[j].Location = new System.Drawing.Point(10 + j * 65, 50);
else if (j > 3 && j <= 7)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 4) * 65, 80);
else if (j > 7 && j <= 11)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 8) * 65, 110);
else if (j > 11 && j <= 15)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 12) * 65, 140);
Buttons[j].Size = new Size(60, 23);
}
for (int j = 0; j < 10; j++)
{
Buttons[j].Text = "" + j + "";
}
for (int j = 10; j < 11; j++)
{ Buttons[j].Text = ".";
}
for (int j = 11; j < 12; j++)
{ Buttons[j].Text = "=";
}
for (int j = 12; j < 13; j++)
{
Buttons[j].Text = "+";
}
for (int j = 13; j < 14; j++)
{
Buttons[j].Text = "-";
}
for (int j = 14; j < 15; j++)
{
Buttons[j].Text = "*";
}
for (int j = 15; j < 16; j++)
{
Buttons[j].Text = "/";
}
}
}
}
-------------------------------------------------------------------------------------------------------------
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
{
System.Windows.Forms.TextBox[] textBoxes;
System.Windows.Forms.Button[] Buttons;
int i = 1, bno,j;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBoxes = new System.Windows.Forms.TextBox[16];
textBoxes[i] = new TextBox();
this.Controls.Add(textBoxes[i]);
textBoxes[i].Location = new System.Drawing.Point(i * 10, 10);
textBoxes[i].Size = new Size(260, 22);
Buttons = new System.Windows.Forms.Button[16];
for (int j = 0; j < 16; j++)
{
Buttons[j] = new Button();
this.Controls.Add(Buttons[j]);
if (j <= 3)
Buttons[j].Location = new System.Drawing.Point(10 + j * 65, 50);
else if (j > 3 && j <= 7)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 4) * 65, 80);
else if (j > 7 && j <= 11)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 8) * 65, 110);
else if (j > 11 && j <= 15)
Buttons[j].Location = new System.Drawing.Point(10 + (j - 12) * 65, 140);
Buttons[j].Size = new Size(60, 23);
}
for (int j = 0; j < 10; j++)
{
Buttons[j].Text = "" + j + "";
}
for (int j = 10; j < 11; j++)
{
Buttons[j].Text = ".";
}
for (int j = 11; j < 12; j++)
{
Buttons[j].Text = "=";
}
for (int j = 12; j < 13; j++)
{
Buttons[j].Text = "+";
}
for (int j = 13; j < 14; j++)
{
Buttons[j].Text = "-";
}
for (int j = 14; j < 15; j++)
{
Buttons[j].Text = "*";
}
for (int j = 15; j < 16; j++)
{
Buttons[j].Text = "/";
}
}
public void Buttons_Click(object sender, EventArgs e)
{
for (int j = 0; j < 10; ++j)
{
Buttons[j].Text = Convert.ToString( j );
for (int i = 1; i < 2; ++i)
{
j = Convert.ToInt16(textBoxes[i].Text);
textBoxes[i].Text=""+j;
}
}
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
/*String tnum = sender.ToString();
int tlen = tnum.Length;
String no = tnum.Substring(tlen);
for (int j = 0; j < 16; j++)
{
if (Buttons[j].Text == no)
bno = j;
}
switch (bno)
{
case 0:
MessageBox.Show("0");
break;
case 1:
MessageBox.Show("1");
break;
case 2:
MessageBox.Show("2");
break;
case 3:
MessageBox.Show("3");
break;
case 4:
MessageBox.Show("4");
break;
case 5:
MessageBox.Show("5");
break;
case 6:
MessageBox.Show("6");
break;
case 7:
MessageBox.Show("7");
break;
case 8:
MessageBox.Show("8");
break;
case 9:
MessageBox.Show("9");
break;
case 10:
MessageBox.Show("10");
break;
case 11:
MessageBox.Show("11");
break;
case 12:
MessageBox.Show("12");
break;
case 13:
MessageBox.Show("13");
break;
case 14:
MessageBox.Show("14");
break;
case 15:
MessageBox.Show("15");
break;
}
*/
}
}
}
2010年11月5日 星期五
99/11/05 HW
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 temp;
int nobtpressed = 0;
int[] recordbutn = new int[9] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
System.Windows.Forms.Button[] Buttons;
int bno;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Buttons = new System.Windows.Forms.Button[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
Buttons[i].Size = new Size(50, 50);
Buttons[i].Click += new System.EventHandler(Buttons_Click);
this.Controls.Add(Buttons[i]);
if (i <= 2)
Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 0 + 10);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 50 + 10);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 100 + 10);
Buttons[i].Text = "" + i + "";
}
}
public void Buttons_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
String tnum = sender.ToString();
int tlen = tnum.Length;
String no = tnum.Substring(tlen - 1);
for (int i = 0; i < 9; i++)
{
if (Buttons[i].Text == no)
bno = i;
}
switch (bno)
{
case 0:
//MessageBox.Show("0");
Buttons[0].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[0];
recordbutn[0] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 1:
//MessageBox.Show("1");
Buttons[1].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[1];
recordbutn[1] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 2:
//MessageBox.Show("2");
Buttons[2].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[2];
recordbutn[2] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 3:
//MessageBox.Show("3");
Buttons[3].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[3];
recordbutn[3] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 4:
//MessageBox.Show("4");
Buttons[4].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[4];
recordbutn[4] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 5:
//MessageBox.Show("5");
Buttons[5].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[5];
recordbutn[5] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 6:
//MessageBox.Show("6");
Buttons[6].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[6];
recordbutn[6] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 7:
//MessageBox.Show("7");
Buttons[7].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[7];
recordbutn[7] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 8:
//MessageBox.Show("8");
Buttons[8].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[8];
recordbutn[8] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
}
}
private void button1_Click(object sender, EventArgs e)
{
Random rd = new Random();
int rdno = rd.Next(9 - nobtpressed);
label1.Text = "" + recordbutn[rdno];
Buttons[recordbutn[rdno]].Image = pictureBox2.Image;
nobtpressed = nobtpressed + 1;
temp = recordbutn[rdno];
recordbutn[rdno] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
label2.Text = "" + nobtpressed;
}
}
}
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 temp;
int nobtpressed = 0;
int[] recordbutn = new int[9] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
System.Windows.Forms.Button[] Buttons;
int bno;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Buttons = new System.Windows.Forms.Button[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
Buttons[i].Size = new Size(50, 50);
Buttons[i].Click += new System.EventHandler(Buttons_Click);
this.Controls.Add(Buttons[i]);
if (i <= 2)
Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 0 + 10);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 50 + 10);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 100 + 10);
Buttons[i].Text = "" + i + "";
}
}
public void Buttons_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
String tnum = sender.ToString();
int tlen = tnum.Length;
String no = tnum.Substring(tlen - 1);
for (int i = 0; i < 9; i++)
{
if (Buttons[i].Text == no)
bno = i;
}
switch (bno)
{
case 0:
//MessageBox.Show("0");
Buttons[0].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[0];
recordbutn[0] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 1:
//MessageBox.Show("1");
Buttons[1].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[1];
recordbutn[1] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 2:
//MessageBox.Show("2");
Buttons[2].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[2];
recordbutn[2] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 3:
//MessageBox.Show("3");
Buttons[3].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[3];
recordbutn[3] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 4:
//MessageBox.Show("4");
Buttons[4].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[4];
recordbutn[4] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 5:
//MessageBox.Show("5");
Buttons[5].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[5];
recordbutn[5] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 6:
//MessageBox.Show("6");
Buttons[6].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[6];
recordbutn[6] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 7:
//MessageBox.Show("7");
Buttons[7].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[7];
recordbutn[7] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
case 8:
//MessageBox.Show("8");
Buttons[8].Image = pictureBox1.Image;
nobtpressed = nobtpressed + 1;
label2.Text = "" + nobtpressed;
temp = recordbutn[8];
recordbutn[8] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
break;
}
}
private void button1_Click(object sender, EventArgs e)
{
Random rd = new Random();
int rdno = rd.Next(9 - nobtpressed);
label1.Text = "" + recordbutn[rdno];
Buttons[recordbutn[rdno]].Image = pictureBox2.Image;
nobtpressed = nobtpressed + 1;
temp = recordbutn[rdno];
recordbutn[rdno] = recordbutn[9 - nobtpressed];
recordbutn[9 - nobtpressed] = temp;
label2.Text = "" + nobtpressed;
}
}
}
訂閱:
文章 (Atom)