產生亂數(案件自己拉)
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 = "";
}
}
}
沒有留言:
張貼留言