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.Button[] Buttons;
System.Windows.Forms.TextBox[] textboxs;
int[,] a = new int[4, 4];
int bno;
Form2 newform;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Buttons = new System.Windows.Forms.Button[9];
textboxs = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
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, 10 + 100);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
for (int j = 0; j < 9; j++)
{
textboxs[j] = new TextBox();
this.Controls.Add(textboxs[j]);
if (j <= 2)
textboxs[j].Location = new System.Drawing.Point(10 + j * 110, 10);
else if (j > 2 && j <= 5)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 3) * 110, 40);
else if (j > 5 && j <= 9)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 6) * 110, 70);
}
textboxs[0].Text = "7";
textboxs[1].Text = "2";
textboxs[2].Text = "4";
textboxs[3].Text = "5";
textboxs[4].Text = "0";
textboxs[5].Text = "6";
textboxs[6].Text = "8";
textboxs[7].Text = "3";
textboxs[8].Text = "1";
}
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 j = 0; j < 9; j++)
{
if (Buttons[j].Text == no)
bno = j;
}
switch (bno)
{
case 0:
if (Buttons[1].Text == "0")
{
String temp;
temp = Buttons[1].Text;
Buttons[1].Text = Buttons[0].Text;
Buttons[0].Text = temp;
}
if (Buttons[3].Text == "0")
{
String temp;
temp = Buttons[3].Text;
Buttons[3].Text = Buttons[0].Text;
Buttons[0].Text = temp;
}
break;
case 1:
if (Buttons[0].Text == "0")
{
String temp;
temp = Buttons[0].Text;
Buttons[0].Text = Buttons[1].Text;
Buttons[1].Text = temp;
}
if (Buttons[2].Text == "0")
{
String temp;
temp = Buttons[2].Text;
Buttons[2].Text = Buttons[1].Text;
Buttons[1].Text = temp;
}
if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].Text = Buttons[1].Text;
Buttons[1].Text = temp;
}
break;
case 2:
if (Buttons[1].Text == "0")
{
String temp;
temp = Buttons[1].Text;
Buttons[1].Text = Buttons[2].Text;
Buttons[2].Text = temp;
}
if (Buttons[5].Text == "0")
{
String temp;
temp = Buttons[5].Text;
Buttons[5].Text = Buttons[2].Text;
Buttons[2].Text = temp;
}
break;
case 3:
if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].Text = Buttons[3].Text;
Buttons[3].Text = temp;
}
if (Buttons[0].Text == "0")
{
String temp;
temp = Buttons[0].Text;
Buttons[0].Text = Buttons[3].Text;
Buttons[3].Text = temp;
}
if (Buttons[6].Text == "0")
{
String temp;
temp = Buttons[6].Text;
Buttons[6].Text = Buttons[3].Text;
Buttons[3].Text = temp;
}
break;
case 4:
if (Buttons[1].Text == "0")
{
String temp;
temp = Buttons[1].Text;
Buttons[1].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
if (Buttons[3].Text == "0")
{
String temp;
temp = Buttons[3].Text;
Buttons[3].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
if (Buttons[5].Text == "0")
{
String temp;
temp = Buttons[5].Text;
Buttons[5].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
if (Buttons[7].Text == "0")
{
String temp;
temp = Buttons[7].Text;
Buttons[7].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
break;
case 5:
if (Buttons[2].Text == "0")
{
String temp;
temp = Buttons[2].Text;
Buttons[2].Text = Buttons[5].Text;
Buttons[5].Text = temp;
}
if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].Text = Buttons[5].Text;
Buttons[5].Text = temp;
}
if (Buttons[8].Text == "0")
{
String temp;
temp = Buttons[8].Text;
Buttons[8].Text = Buttons[5].Text;
Buttons[5].Text = temp;
}
break;
case 6:
if (Buttons[3].Text == "0")
{
String temp;
temp = Buttons[3].Text;
Buttons[3].Text = Buttons[6].Text;
Buttons[6].Text = temp;
}
if (Buttons[7].Text == "0")
{
String temp;
temp = Buttons[7].Text;
Buttons[7].Text = Buttons[6].Text;
Buttons[6].Text = temp;
}
break;
case 7:
if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].Text = Buttons[7].Text;
Buttons[7].Text = temp;
}
if (Buttons[6].Text == "0")
{
String temp;
temp = Buttons[6].Text;
Buttons[6].Text = Buttons[7].Text;
Buttons[7].Text = temp;
}
if (Buttons[8].Text == "0")
{
String temp;
temp = Buttons[8].Text;
Buttons[8].Text = Buttons[7].Text;
Buttons[7].Text = temp;
}
break;
case 8:
if (Buttons[5].Text == "0")
{
String temp;
temp = Buttons[5].Text;
Buttons[5].Text = Buttons[8].Text;
Buttons[8].Text = temp;
}
if (Buttons[7].Text == "0")
{
String temp;
temp = Buttons[7].Text;
Buttons[7].Text = Buttons[8].Text;
Buttons[8].Text = temp;
}
break;
}
}
private void button1_Click(object sender, EventArgs e)
{ //輸入 input
for (int i = 0; i < 9; i++)
{
if(i <= 2)
a[1, i+1] = Convert.ToInt16(textboxs[i].Text);
else if(i > 2 && i <= 5)
a[2, (i-3)+1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 5 && i <= 9)
a[3, (i-6)+1] = Convert.ToInt16(textboxs[i].Text);
}
//輸出 output
for (int j = 0; j < 9; j++ )
if (j <= 2)
Buttons[j].Text = Convert.ToString(a[1, j+1]);
else if (j > 2 && j <= 5)
Buttons[j].Text = Convert.ToString(a[2, (j-3)+1]);
else if (j > 5 && j <= 9)
Buttons[j].Text = Convert.ToString(a[3, (j-6)+1]);
}
private void button2_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.Show();
}
}
}
順序 5-7-2-5-6-1-3--8-7-6-1-3-8-7-6-1-3-4-5--2-1-3-4-5-2-1
共26步
2010年10月29日 星期五
2010年10月22日 星期五
10/15 上課作業
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
System.Windows.Forms.TextBox[] textboxs;
int[,] a = new int[5, 5];
int[,] b = new int[5, 5];
int[,] c = new int[5, 5];
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
textboxs = new System.Windows.Forms.TextBox[48];
for (int j = 0; j < 48; j++)
{
textboxs[j] = new TextBox();
this.Controls.Add(textboxs[j]);
if (j <= 3)
textboxs[j].Location = new System.Drawing.Point(10 + j * 110, 10);
else if (j > 3 && j <= 7)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 4) * 110, 40);
else if (j > 7 && j <= 11)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 8) * 110, 70);
else if (j > 11 && j <= 15)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 12) * 110, 100);
else if (j > 15 && j <= 19)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 16) * 110, 140);
else if (j > 19 && j <= 23)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 20) * 110, 170);
else if (j > 23 && j <= 27)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 24) * 110, 200);
else if (j > 27 && j <= 31)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 28) * 110, 230);
else if (j > 31 && j <= 35)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 32) * 110, 270);
else if (j > 35 && j <= 39)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 36) * 110, 300);
else if (j > 39 && j <= 43)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 40) * 110, 330);
else if (j > 43 && j <= 47)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 44) * 110, 360);
}
textboxs[0].Text = "1";
textboxs[1].Text = "0";
textboxs[2].Text = "0";
textboxs[3].Text = "0";
textboxs[4].Text = "0";
textboxs[5].Text = "1";
textboxs[6].Text = "0";
textboxs[7].Text = "0";
textboxs[8].Text = "0";
textboxs[9].Text = "0";
textboxs[10].Text = "1";
textboxs[11].Text = "0";
textboxs[12].Text = "0";
textboxs[13].Text = "0";
textboxs[14].Text = "0";
textboxs[15].Text = "1";
textboxs[16].Text = "1";
textboxs[17].Text = "0";
textboxs[18].Text = "0";
textboxs[19].Text = "0";
textboxs[20].Text = "0";
textboxs[21].Text = "1";
textboxs[22].Text = "0";
textboxs[23].Text = "0";
textboxs[24].Text = "0";
textboxs[25].Text = "0";
textboxs[26].Text = "1";
textboxs[27].Text = "0";
textboxs[28].Text = "0";
textboxs[29].Text = "0";
textboxs[30].Text = "0";
textboxs[31].Text = "1";
}
private void button1_Click(object sender, EventArgs e)
{
//輸入 intput
for (int i = 0; i < 16; i++)
{
if (i <= 3)
a[1, i + 1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 3 && i <= 7)
a[2, (i - 4) + 1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 7 && i <= 11)
a[3, (i - 8) + 1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 11 && i <= 15)
a[4, (i - 12) + 1] = Convert.ToInt16(textboxs[i].Text);
}
for (int i = 0; i < 16; i++)
{
if (i <= 3)
b[1, i + 1] = Convert.ToInt16(textboxs[(i+16)].Text);
else if (i > 3 && i <= 7)
b[2, (i - 4) + 1] = Convert.ToInt16(textboxs[(i+16)].Text);
else if (i > 7 && i <= 11)
b[3, (i - 8) + 1] = Convert.ToInt16(textboxs[(i+16)].Text);
else if (i > 11 && i <= 15)
b[4, (i - 12) + 1] = Convert.ToInt16(textboxs[(i+16)].Text);
}
c[1, 1] = a[1, 1] * b[1, 1] + a[1, 2] * b[2, 1] + a[1, 3] * b[3, 1] + a[1, 4] * b[4, 1];
c[1, 2] = a[1, 1] * b[1, 2] + a[1, 2] * b[2, 2] + a[1, 3] * b[3, 2] + a[1, 4] * b[4, 2];
c[1, 3] = a[1, 1] * b[1, 3] + a[1, 2] * b[2, 3] + a[1, 3] * b[3, 3] + a[1, 4] * b[4, 3];
c[1, 4] = a[1, 1] * b[1, 4] + a[1, 2] * b[2, 4] + a[1, 3] * b[3, 4] + a[1, 4] * b[4, 4];
c[2, 1] = a[2, 1] * b[1, 1] + a[2, 2] * b[2, 1] + a[2, 3] * b[3, 1] + a[2, 4] * b[4, 1];
c[2, 2] = a[2, 1] * b[1, 2] + a[2, 2] * b[2, 2] + a[2, 3] * b[3, 2] + a[2, 4] * b[4, 2];
c[2, 3] = a[2, 1] * b[1, 3] + a[2, 2] * b[2, 3] + a[2, 3] * b[3, 3] + a[2, 4] * b[4, 3];
c[2, 4] = a[2, 1] * b[1, 4] + a[2, 2] * b[2, 4] + a[2, 3] * b[3, 4] + a[2, 4] * b[4, 4];
c[3, 1] = a[3, 1] * b[1, 1] + a[3, 2] * b[2, 1] + a[3, 3] * b[3, 1] + a[3, 4] * b[4, 1];
c[3, 2] = a[3, 1] * b[1, 2] + a[3, 2] * b[2, 2] + a[3, 3] * b[3, 2] + a[3, 4] * b[4, 2];
c[3, 3] = a[3, 1] * b[1, 3] + a[3, 2] * b[2, 3] + a[3, 3] * b[3, 3] + a[3, 4] * b[4, 3];
c[3, 4] = a[3, 1] * b[1, 4] + a[3, 2] * b[2, 4] + a[3, 3] * b[3, 4] + a[3, 4] * b[4, 4];
c[4, 1] = a[4, 1] * b[1, 1] + a[4, 2] * b[2, 1] + a[4, 3] * b[3, 1] + a[4, 4] * b[4, 1];
c[4, 2] = a[4, 1] * b[1, 2] + a[4, 2] * b[2, 2] + a[4, 3] * b[3, 2] + a[4, 4] * b[4, 2];
c[4, 3] = a[4, 1] * b[1, 3] + a[4, 2] * b[2, 3] + a[4, 3] * b[3, 3] + a[4, 4] * b[4, 3];
c[4, 4] = a[4, 1] * b[1, 4] + a[4, 2] * b[2, 4] + a[4, 3] * b[3, 4] + a[4, 4] * b[4, 4];
textboxs[32].Text = "" + c[1, 1];
textboxs[33].Text = "" + c[1, 2];
textboxs[34].Text = "" + c[1, 3];
textboxs[35].Text = "" + c[1, 4];
textboxs[36].Text = "" + c[2, 1];
textboxs[37].Text = "" + c[2, 2];
textboxs[38].Text = "" + c[2, 3];
textboxs[39].Text = "" + c[2, 4];
textboxs[40].Text = "" + c[3, 1];
textboxs[41].Text = "" + c[3, 2];
textboxs[42].Text = "" + c[3, 3];
textboxs[43].Text = "" + c[3, 4];
textboxs[44].Text = "" + c[4, 1];
textboxs[45].Text = "" + c[4, 2];
textboxs[46].Text = "" + c[4, 3];
textboxs[47].Text = "" + c[4, 4];
}
}
}
{
public partial class Form2 : Form
{
System.Windows.Forms.TextBox[] textboxs;
int[,] a = new int[5, 5];
int[,] b = new int[5, 5];
int[,] c = new int[5, 5];
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
textboxs = new System.Windows.Forms.TextBox[48];
for (int j = 0; j < 48; j++)
{
textboxs[j] = new TextBox();
this.Controls.Add(textboxs[j]);
if (j <= 3)
textboxs[j].Location = new System.Drawing.Point(10 + j * 110, 10);
else if (j > 3 && j <= 7)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 4) * 110, 40);
else if (j > 7 && j <= 11)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 8) * 110, 70);
else if (j > 11 && j <= 15)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 12) * 110, 100);
else if (j > 15 && j <= 19)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 16) * 110, 140);
else if (j > 19 && j <= 23)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 20) * 110, 170);
else if (j > 23 && j <= 27)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 24) * 110, 200);
else if (j > 27 && j <= 31)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 28) * 110, 230);
else if (j > 31 && j <= 35)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 32) * 110, 270);
else if (j > 35 && j <= 39)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 36) * 110, 300);
else if (j > 39 && j <= 43)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 40) * 110, 330);
else if (j > 43 && j <= 47)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 44) * 110, 360);
}
textboxs[0].Text = "1";
textboxs[1].Text = "0";
textboxs[2].Text = "0";
textboxs[3].Text = "0";
textboxs[4].Text = "0";
textboxs[5].Text = "1";
textboxs[6].Text = "0";
textboxs[7].Text = "0";
textboxs[8].Text = "0";
textboxs[9].Text = "0";
textboxs[10].Text = "1";
textboxs[11].Text = "0";
textboxs[12].Text = "0";
textboxs[13].Text = "0";
textboxs[14].Text = "0";
textboxs[15].Text = "1";
textboxs[16].Text = "1";
textboxs[17].Text = "0";
textboxs[18].Text = "0";
textboxs[19].Text = "0";
textboxs[20].Text = "0";
textboxs[21].Text = "1";
textboxs[22].Text = "0";
textboxs[23].Text = "0";
textboxs[24].Text = "0";
textboxs[25].Text = "0";
textboxs[26].Text = "1";
textboxs[27].Text = "0";
textboxs[28].Text = "0";
textboxs[29].Text = "0";
textboxs[30].Text = "0";
textboxs[31].Text = "1";
}
private void button1_Click(object sender, EventArgs e)
{
//輸入 intput
for (int i = 0; i < 16; i++)
{
if (i <= 3)
a[1, i + 1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 3 && i <= 7)
a[2, (i - 4) + 1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 7 && i <= 11)
a[3, (i - 8) + 1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 11 && i <= 15)
a[4, (i - 12) + 1] = Convert.ToInt16(textboxs[i].Text);
}
for (int i = 0; i < 16; i++)
{
if (i <= 3)
b[1, i + 1] = Convert.ToInt16(textboxs[(i+16)].Text);
else if (i > 3 && i <= 7)
b[2, (i - 4) + 1] = Convert.ToInt16(textboxs[(i+16)].Text);
else if (i > 7 && i <= 11)
b[3, (i - 8) + 1] = Convert.ToInt16(textboxs[(i+16)].Text);
else if (i > 11 && i <= 15)
b[4, (i - 12) + 1] = Convert.ToInt16(textboxs[(i+16)].Text);
}
c[1, 1] = a[1, 1] * b[1, 1] + a[1, 2] * b[2, 1] + a[1, 3] * b[3, 1] + a[1, 4] * b[4, 1];
c[1, 2] = a[1, 1] * b[1, 2] + a[1, 2] * b[2, 2] + a[1, 3] * b[3, 2] + a[1, 4] * b[4, 2];
c[1, 3] = a[1, 1] * b[1, 3] + a[1, 2] * b[2, 3] + a[1, 3] * b[3, 3] + a[1, 4] * b[4, 3];
c[1, 4] = a[1, 1] * b[1, 4] + a[1, 2] * b[2, 4] + a[1, 3] * b[3, 4] + a[1, 4] * b[4, 4];
c[2, 1] = a[2, 1] * b[1, 1] + a[2, 2] * b[2, 1] + a[2, 3] * b[3, 1] + a[2, 4] * b[4, 1];
c[2, 2] = a[2, 1] * b[1, 2] + a[2, 2] * b[2, 2] + a[2, 3] * b[3, 2] + a[2, 4] * b[4, 2];
c[2, 3] = a[2, 1] * b[1, 3] + a[2, 2] * b[2, 3] + a[2, 3] * b[3, 3] + a[2, 4] * b[4, 3];
c[2, 4] = a[2, 1] * b[1, 4] + a[2, 2] * b[2, 4] + a[2, 3] * b[3, 4] + a[2, 4] * b[4, 4];
c[3, 1] = a[3, 1] * b[1, 1] + a[3, 2] * b[2, 1] + a[3, 3] * b[3, 1] + a[3, 4] * b[4, 1];
c[3, 2] = a[3, 1] * b[1, 2] + a[3, 2] * b[2, 2] + a[3, 3] * b[3, 2] + a[3, 4] * b[4, 2];
c[3, 3] = a[3, 1] * b[1, 3] + a[3, 2] * b[2, 3] + a[3, 3] * b[3, 3] + a[3, 4] * b[4, 3];
c[3, 4] = a[3, 1] * b[1, 4] + a[3, 2] * b[2, 4] + a[3, 3] * b[3, 4] + a[3, 4] * b[4, 4];
c[4, 1] = a[4, 1] * b[1, 1] + a[4, 2] * b[2, 1] + a[4, 3] * b[3, 1] + a[4, 4] * b[4, 1];
c[4, 2] = a[4, 1] * b[1, 2] + a[4, 2] * b[2, 2] + a[4, 3] * b[3, 2] + a[4, 4] * b[4, 2];
c[4, 3] = a[4, 1] * b[1, 3] + a[4, 2] * b[2, 3] + a[4, 3] * b[3, 3] + a[4, 4] * b[4, 3];
c[4, 4] = a[4, 1] * b[1, 4] + a[4, 2] * b[2, 4] + a[4, 3] * b[3, 4] + a[4, 4] * b[4, 4];
textboxs[32].Text = "" + c[1, 1];
textboxs[33].Text = "" + c[1, 2];
textboxs[34].Text = "" + c[1, 3];
textboxs[35].Text = "" + c[1, 4];
textboxs[36].Text = "" + c[2, 1];
textboxs[37].Text = "" + c[2, 2];
textboxs[38].Text = "" + c[2, 3];
textboxs[39].Text = "" + c[2, 4];
textboxs[40].Text = "" + c[3, 1];
textboxs[41].Text = "" + c[3, 2];
textboxs[42].Text = "" + c[3, 3];
textboxs[43].Text = "" + c[3, 4];
textboxs[44].Text = "" + c[4, 1];
textboxs[45].Text = "" + c[4, 2];
textboxs[46].Text = "" + c[4, 3];
textboxs[47].Text = "" + c[4, 4];
}
}
}
10/22 上課課題
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
System.Windows.Forms.Button[] Buttons;
System.Windows.Forms.TextBox[] textboxs;
int[,] a = new int[4, 4];
Form2 newform;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Buttons = new System.Windows.Forms.Button[9];
textboxs = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
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, 10 + 100);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
for (int j = 0; j < 9; j++)
{
textboxs[j] = new TextBox();
this.Controls.Add(textboxs[j]);
if (j <= 2)
textboxs[j].Location = new System.Drawing.Point(10 + j * 110, 10);
else if (j > 2 && j <= 5)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 3) * 110, 40);
else if (j > 5 && j <= 9)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 6) * 110, 70);
}
textboxs[0].Text = "7";
textboxs[1].Text = "2";
textboxs[2].Text = "4";
textboxs[3].Text = "5";
textboxs[4].Text = "0";
textboxs[5].Text = "6";
textboxs[6].Text = "8";
textboxs[7].Text = "3";
textboxs[8].Text = "1";
}
public void Buttons_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
MessageBox.Show("" + sender.ToString());
}
private void button1_Click(object sender, EventArgs e)
{ //輸入 input
for (int i = 0; i < 9; i++)
{
if(i <= 2)
a[1, i+1] = Convert.ToInt16(textboxs[i].Text);
else if(i > 2 && i <= 5)
a[2, (i-3)+1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 5 && i <= 9)
a[3, (i-6)+1] = Convert.ToInt16(textboxs[i].Text);
}
//輸出 output
for (int j = 0; j < 9; j++ )
if (j <= 2)
Buttons[j].Text = Convert.ToString(a[1, j+1]);
else if (j > 2 && j <= 5)
Buttons[j].Text = Convert.ToString(a[2, (j-3)+1]);
else if (j > 5 && j <= 9)
Buttons[j].Text = Convert.ToString(a[3, (j-6)+1]);
}
private void button2_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.Show();
}
}
}
{
public partial class Form1 : Form
{
System.Windows.Forms.Button[] Buttons;
System.Windows.Forms.TextBox[] textboxs;
int[,] a = new int[4, 4];
Form2 newform;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Buttons = new System.Windows.Forms.Button[9];
textboxs = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
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, 10 + 100);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
for (int j = 0; j < 9; j++)
{
textboxs[j] = new TextBox();
this.Controls.Add(textboxs[j]);
if (j <= 2)
textboxs[j].Location = new System.Drawing.Point(10 + j * 110, 10);
else if (j > 2 && j <= 5)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 3) * 110, 40);
else if (j > 5 && j <= 9)
textboxs[j].Location = new System.Drawing.Point(10 + (j - 6) * 110, 70);
}
textboxs[0].Text = "7";
textboxs[1].Text = "2";
textboxs[2].Text = "4";
textboxs[3].Text = "5";
textboxs[4].Text = "0";
textboxs[5].Text = "6";
textboxs[6].Text = "8";
textboxs[7].Text = "3";
textboxs[8].Text = "1";
}
public void Buttons_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
MessageBox.Show("" + sender.ToString());
}
private void button1_Click(object sender, EventArgs e)
{ //輸入 input
for (int i = 0; i < 9; i++)
{
if(i <= 2)
a[1, i+1] = Convert.ToInt16(textboxs[i].Text);
else if(i > 2 && i <= 5)
a[2, (i-3)+1] = Convert.ToInt16(textboxs[i].Text);
else if (i > 5 && i <= 9)
a[3, (i-6)+1] = Convert.ToInt16(textboxs[i].Text);
}
//輸出 output
for (int j = 0; j < 9; j++ )
if (j <= 2)
Buttons[j].Text = Convert.ToString(a[1, j+1]);
else if (j > 2 && j <= 5)
Buttons[j].Text = Convert.ToString(a[2, (j-3)+1]);
else if (j > 5 && j <= 9)
Buttons[j].Text = Convert.ToString(a[3, (j-6)+1]);
}
private void button2_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.Show();
}
}
}
2010年10月8日 星期五
3*3矩陣
int[,] a = new int[4, 4];
int[,] b = new int[4, 4];
int[,] c = new int[4, 4];
a[1,1]=int.Parse(textBox1.Text);
a[1,2]=int.Parse(textBox4.Text);
a[1,3]=int.Parse(textBox7.Text);
a[2,1]=int.Parse(textBox2.Text);
a[2,2]=int.Parse(textBox5.Text);
a[2,3]=int.Parse(textBox8.Text);
a[3,1]=int.Parse(textBox3.Text);
a[3,2]=int.Parse(textBox6.Text);
a[3,3]=int.Parse(textBox9.Text);
b[1,1]=int.Parse(textBox10.Text);
b[1,2]=int.Parse(textBox13.Text);
b[1,3]=int.Parse(textBox16.Text);
b[2,1]=int.Parse(textBox11.Text);
b[2,2]=int.Parse(textBox14.Text);
b[2,3]=int.Parse(textBox17.Text);
b[3,1]=int.Parse(textBox12.Text);
b[3,2]=int.Parse(textBox15.Text);
b[3,3]=int.Parse(textBox18.Text);
c[1,1]=a[1,1]*b[1,1]+a[1,2]*b[2,1]+a[1,3]*b[3,1];
c[1,2]=a[1,1]*b[1,2]+a[1,2]*b[2,2]+a[1,3]*b[3,2];
c[1,3]=a[1,1]*b[1,3]+a[1,2]*b[2,3]+a[1,3]*b[3,3];
c[2,1]=a[2,1]*b[1,1]+a[2,2]*b[2,1]+a[2,3]*b[3,1];
c[2,2]=a[2,1]*b[1,2]+a[2,2]*b[2,2]+a[2,3]*b[3,2];
c[2,3]=a[2,1]*b[1,3]+a[2,2]*b[2,3]+a[2,3]*b[3,3];
c[3,1]=a[3,1]*b[1,1]+a[3,2]*b[2,1]+a[3,3]*b[3,1];
c[3,2]=a[3,1]*b[1,2]+a[3,2]*b[2,2]+a[3,3]*b[3,2];
c[3,3]=a[3,1]*b[1,3]+a[3,2]*b[2,3]+a[3,3]*b[3,3];
textBox19.Text=""+c[1,1];
textBox22.Text=""+c[1,2];
textBox25.Text=""+c[1,3];
textBox20.Text=""+c[2,1];
textBox23.Text=""+c[2,2];
textBox26.Text=""+c[2,3];
textBox21.Text=""+c[3,1];
textBox24.Text=""+c[3,2];
textBox27.Text=""+c[3,3];
int[,] b = new int[4, 4];
int[,] c = new int[4, 4];
a[1,1]=int.Parse(textBox1.Text);
a[1,2]=int.Parse(textBox4.Text);
a[1,3]=int.Parse(textBox7.Text);
a[2,1]=int.Parse(textBox2.Text);
a[2,2]=int.Parse(textBox5.Text);
a[2,3]=int.Parse(textBox8.Text);
a[3,1]=int.Parse(textBox3.Text);
a[3,2]=int.Parse(textBox6.Text);
a[3,3]=int.Parse(textBox9.Text);
b[1,1]=int.Parse(textBox10.Text);
b[1,2]=int.Parse(textBox13.Text);
b[1,3]=int.Parse(textBox16.Text);
b[2,1]=int.Parse(textBox11.Text);
b[2,2]=int.Parse(textBox14.Text);
b[2,3]=int.Parse(textBox17.Text);
b[3,1]=int.Parse(textBox12.Text);
b[3,2]=int.Parse(textBox15.Text);
b[3,3]=int.Parse(textBox18.Text);
c[1,1]=a[1,1]*b[1,1]+a[1,2]*b[2,1]+a[1,3]*b[3,1];
c[1,2]=a[1,1]*b[1,2]+a[1,2]*b[2,2]+a[1,3]*b[3,2];
c[1,3]=a[1,1]*b[1,3]+a[1,2]*b[2,3]+a[1,3]*b[3,3];
c[2,1]=a[2,1]*b[1,1]+a[2,2]*b[2,1]+a[2,3]*b[3,1];
c[2,2]=a[2,1]*b[1,2]+a[2,2]*b[2,2]+a[2,3]*b[3,2];
c[2,3]=a[2,1]*b[1,3]+a[2,2]*b[2,3]+a[2,3]*b[3,3];
c[3,1]=a[3,1]*b[1,1]+a[3,2]*b[2,1]+a[3,3]*b[3,1];
c[3,2]=a[3,1]*b[1,2]+a[3,2]*b[2,2]+a[3,3]*b[3,2];
c[3,3]=a[3,1]*b[1,3]+a[3,2]*b[2,3]+a[3,3]*b[3,3];
textBox19.Text=""+c[1,1];
textBox22.Text=""+c[1,2];
textBox25.Text=""+c[1,3];
textBox20.Text=""+c[2,1];
textBox23.Text=""+c[2,2];
textBox26.Text=""+c[2,3];
textBox21.Text=""+c[3,1];
textBox24.Text=""+c[3,2];
textBox27.Text=""+c[3,3];
2010年10月1日 星期五
99乘法表
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add("1*1=1 1*2= 2 1*3= 3 1*4= 4 1*5= 5 1*6= 6 1*7= 7 1*8= 8 1*9= 9");
listBox1.Items.Add("2*1=2 2*2= 4 2*3= 6 2*4= 8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18");
listBox1.Items.Add("3*1=3 3*2= 6 3*3= 9 3*4=14 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27");
listBox1.Items.Add("4*1=4 4*2= 8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36");
listBox1.Items.Add("5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45");
listBox1.Items.Add("6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54");
listBox1.Items.Add("7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63");
listBox1.Items.Add("8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72");
listBox1.Items.Add("9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81");
{
listBox1.Items.Add("1*1=1 1*2= 2 1*3= 3 1*4= 4 1*5= 5 1*6= 6 1*7= 7 1*8= 8 1*9= 9");
listBox1.Items.Add("2*1=2 2*2= 4 2*3= 6 2*4= 8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18");
listBox1.Items.Add("3*1=3 3*2= 6 3*3= 9 3*4=14 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27");
listBox1.Items.Add("4*1=4 4*2= 8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36");
listBox1.Items.Add("5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45");
listBox1.Items.Add("6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54");
listBox1.Items.Add("7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63");
listBox1.Items.Add("8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72");
listBox1.Items.Add("9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81");
訂閱:
文章 (Atom)