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[] Button1;
System.Windows.Forms.TextBox[] TextBox1;
int[,] a = new int[4, 4];
int bno;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Button1 = new System.Windows.Forms.Button[9];
TextBox1 = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
Button1[i] = new Button();
Button1[i].Click += new System.EventHandler(Button1_Click);
this.Controls.Add(Button1[i]);
if (i <= 2)
Button1[i].Location = new System.Drawing.Point(10 + i * 80, 10 + 100);
else if (i > 2 && i <= 5)
Button1[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Button1[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
for (int i = 0; i < 9; ++i)
{
TextBox1[i] = new TextBox();
this.Controls.Add(TextBox1[i]);
if (i <= 2)
TextBox1[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 2 && i <= 5)
TextBox1[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40);
else if (i > 5 && i <= 9)
TextBox1[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 70);
}
TextBox1[0].Text = "7";
TextBox1[1].Text = "2";
TextBox1[2].Text = "4";
TextBox1[3].Text = "5";
TextBox1[4].Text = "0";
TextBox1[5].Text = "6";
TextBox1[6].Text = "8";
TextBox1[7].Text = "3";
TextBox1[8].Text = "1";
}
public void Button1_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
//MessageBox.Show(Convert.ToString(((Button)sender).Text));
String tnum = sender.ToString();
int tlen = tnum.Length;
String no = tnum.Substring(tlen - 1);
for (int i = 0; i < 9; i++)
{
if (Button1[i].Text == no)
// MessageBox.Show("" + no);
bno = i;
}
// MessageBox.Show(""+bno);
switch (bno)
{
case 0:
// MessageBox.Show("0");
if (Button1[1].Text == "0")
{
String temp;
temp = Button1[1].Text;
Button1[1].Text = Button1[0].Text;
Button1[0].Text = temp;
}
else if (Button1[3].Text == "0")
{
String temp;
temp = Button1[3].Text;
Button1[3].Text = Button1[0].Text;
Button1[0].Text = temp;
}
break;
case 1:
// MessageBox.Show("1");
if (Button1[4].Text =="0")
{
String temp;
temp = Button1[4].Text;
Button1[4].Text = Button1[1].Text;
Button1[1].Text = temp;
}
else if (Button1[0].Text == "0")
{
String temp;
temp = Button1[0].Text;
Button1[0].Text = Button1[1].Text;
Button1[1].Text = temp;
}
else if (Button1[2].Text == "0")
{
String temp;
temp = Button1[2].Text;
Button1[2].Text = Button1[1].Text;
Button1[1].Text = temp;
}
break;
case 2:
// MessageBox.Show("2");
if (Button1[1].Text == "0")
{
String temp;
temp = Button1[1].Text;
Button1[1].Text = Button1[2].Text;
Button1[2].Text = temp;
}
else if (Button1[5].Text == "0")
{
String temp;
temp = Button1[5].Text;
Button1[5].Text = Button1[2].Text;
Button1[2].Text = temp;
}
break;
case 3:
//MessageBox.Show("3");
if (Button1[0].Text == "0")
{
String temp;
temp = Button1[0].Text;
Button1[0].Text = Button1[3].Text;
Button1[3].Text = temp;
}
else if (Button1[4].Text == "0")
{
String temp;
temp = Button1[4].Text;
Button1[4].Text = Button1[3].Text;
Button1[3].Text = temp;
}
else if (Button1[6].Text == "0")
{
String temp;
temp = Button1[6].Text;
Button1[6].Text = Button1[3].Text;
Button1[3].Text = temp;
}
break;
case 4:
//MessageBox.Show("4");
if (Button1[1].Text == "0")
{
String temp;
temp = Button1[4].Text;
Button1[4].Text = Button1[1].Text;
Button1[1].Text = temp;
}
else if (Button1[3].Text == "0")
{
String temp;
temp = Button1[3].Text;
Button1[3].Text = Button1[4].Text;
Button1[4].Text = temp;
}
else if (Button1[5].Text == "0")
{
String temp;
temp = Button1[5].Text;
Button1[5].Text = Button1[4].Text;
Button1[4].Text = temp;
}
else if (Button1[7].Text == "0")
{
String temp;
temp = Button1[7].Text;
Button1[7].Text = Button1[4].Text;
Button1[4].Text = temp;
}
break;
case 5:
// MessageBox.Show("5");
if (Button1[2].Text == "0")
{
String temp;
temp = Button1[2].Text;
Button1[2].Text = Button1[5].Text;
Button1[5].Text = temp;
}
else if (Button1[4].Text == "0")
{
String temp;
temp = Button1[4].Text;
Button1[4].Text = Button1[5].Text;
Button1[5].Text = temp;
}
else if (Button1[8].Text == "0")
{
String temp;
temp = Button1[8].Text;
Button1[8].Text = Button1[5].Text;
Button1[5].Text = temp;
}
break;
case 6:
// MessageBox.Show("6");
if (Button1[3].Text == "0")
{
String temp;
temp = Button1[3].Text;
Button1[3].Text = Button1[6].Text;
Button1[6].Text = temp;
}
else if (Button1[7].Text == "0")
{
String temp;
temp = Button1[7].Text;
Button1[7].Text = Button1[6].Text;
Button1[6].Text = temp;
}
break;
case 7:
// MessageBox.Show("7");
if (Button1[4].Text == "0")
{
String temp;
temp = Button1[4].Text;
Button1[4].Text = Button1[7].Text;
Button1[7].Text = temp;
}
else if (Button1[6].Text == "0")
{
String temp;
temp = Button1[6].Text;
Button1[6].Text = Button1[7].Text;
Button1[7].Text = temp;
}
else if (Button1[8].Text == "0")
{
String temp;
temp = Button1[8].Text;
Button1[8].Text = Button1[7].Text;
Button1[7].Text = temp;
}
break;
case 8:
// MessageBox.Show("8");
if (Button1[5].Text == "0")
{
String temp;
temp = Button1[5].Text;
Button1[5].Text = Button1[8].Text;
Button1[8].Text = temp;
}
else if (Button1[7].Text == "0")
{
String temp;
temp = Button1[7].Text;
Button1[7].Text = Button1[8].Text;
Button1[8].Text = temp;
}
break;
}
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
//輸入
for (int j = 0; j < 9; j++)
{
if (j < 3)
{
a[1, j + 1] = Convert.ToInt16(TextBox1[j].Text);
}
else if (j >= 3 && j < 6)
{
a[2, j - 2] = Convert.ToInt16(TextBox1[j].Text);
}
else
{
a[3, j - 5] = Convert.ToInt16(TextBox1[j].Text);
}
//輸出
for (int i = 0; i < 9; i++)
{
if (i < 3)
{
Button1[i].Text = Convert.ToString(a[1, i + 1]);
}
else if (i >= 3 && i < 6)
{
Button1[i].Text = Convert.ToString(a[2, i - 2]);
}
else
{
Button1[i].Text = Convert.ToString(a[3, i - 5]);
}
}
}
}
}
}
2010年10月29日 星期五
2010年10月22日 星期五
2010/10/15 按鈕陣列 乘法矩陣 2010/10/22補上
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[] TextBox1;
System.Windows.Forms.TextBox[] TextBox2;
System.Windows.Forms.Button[] Button3;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
TextBox1 = new System.Windows.Forms.TextBox[16];
TextBox2 = new System.Windows.Forms.TextBox[16];
Button3 = new System.Windows.Forms.Button[16];
for (int d = 0; d < 16; d++)
{
TextBox1[d] = new TextBox();
this.Controls.Add(TextBox1[d]);
if (d <= 3)
TextBox1[d].Location = new System.Drawing.Point(10 + d * 100, 10);
else if (d > 3 && d <= 7)
TextBox1[d].Location = new System.Drawing.Point(10 + (d - 4) * 100, 40);
else if (d > 7 && d <= 11)
TextBox1[d].Location = new System.Drawing.Point(10 + (d - 8) * 100, 70);
else if (d > 11 && d <= 16)
TextBox1[d].Location = new System.Drawing.Point(10 + (d - 12) * 100, 100);
}
for (int f = 0; f < 16; f++)
{
TextBox2[f] = new TextBox();
this.Controls.Add(TextBox2[f]);
if (f <= 3)
TextBox2[f].Location = new System.Drawing.Point(10 + f * 100, 10 + 130);
else if (f > 3 && f <= 7)
TextBox2[f].Location = new System.Drawing.Point(10 + (f - 4) * 100, 40 + 130);
else if (f > 7 && f <= 11)
TextBox2[f].Location = new System.Drawing.Point(10 + (f - 8) * 100, 70 + 130);
else if (f > 11 && f <= 16)
TextBox2[f].Location = new System.Drawing.Point(10 + (f - 12) * 100, 100 + 130);
}
for (int g = 0; g < 16; g++)
{
Button3[g] = new Button();
this.Controls.Add(Button3[g]);
if (g <= 3)
Button3[g].Location = new System.Drawing.Point(10 + g * 80, 10 + 130 + 130);
else if (g > 3 && g <= 7)
Button3[g].Location = new System.Drawing.Point(10 + (g - 4) * 80, 40 + 130 + 130);
else if (g > 7 && g <= 11)
Button3[g].Location = new System.Drawing.Point(10 + (g - 8) * 80, 70 + 130 + 130);
else if (g > 11 && g <= 16)
Button3[g].Location = new System.Drawing.Point(10 + (g - 12) * 80, 100 + 130 + 130);
}
}
private void button2_Click(object sender, EventArgs e)
{
int[,] a = new int[5, 5];
int[,] b = new int[5, 5];
int[,] c = new int[5, 5];
int m, n;
m = 5;
n = 5;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < m; k++)
{
c[i, j] = c[i, j] + a[i, k] * b[k, j];
}
a[1, 1] = Convert.ToInt16(TextBox1[0].Text);
a[1, 2] = Convert.ToInt16(TextBox1[1].Text);
a[1, 3] = Convert.ToInt16(TextBox1[2].Text);
a[1, 4] = Convert.ToInt16(TextBox1[3].Text);
a[2, 1] = Convert.ToInt16(TextBox1[4].Text);
a[2, 2] = Convert.ToInt16(TextBox1[5].Text);
a[2, 3] = Convert.ToInt16(TextBox1[6].Text);
a[2, 4] = Convert.ToInt16(TextBox1[7].Text);
a[3, 1] = Convert.ToInt16(TextBox1[8].Text);
a[3, 2] = Convert.ToInt16(TextBox1[9].Text);
a[3, 3] = Convert.ToInt16(TextBox1[10].Text);
a[3, 4] = Convert.ToInt16(TextBox1[11].Text);
a[4, 1] = Convert.ToInt16(TextBox1[12].Text);
a[4, 2] = Convert.ToInt16(TextBox1[13].Text);
a[4, 3] = Convert.ToInt16(TextBox1[14].Text);
a[4, 4] = Convert.ToInt16(TextBox1[15].Text);
b[1, 1] = Convert.ToInt16(TextBox2[0].Text);
b[1, 2] = Convert.ToInt16(TextBox2[1].Text);
b[1, 3] = Convert.ToInt16(TextBox2[2].Text);
b[1, 4] = Convert.ToInt16(TextBox2[3].Text);
b[2, 1] = Convert.ToInt16(TextBox2[4].Text);
b[2, 2] = Convert.ToInt16(TextBox2[5].Text);
b[2, 3] = Convert.ToInt16(TextBox2[6].Text);
b[2, 4] = Convert.ToInt16(TextBox2[7].Text);
b[3, 1] = Convert.ToInt16(TextBox2[8].Text);
b[3, 2] = Convert.ToInt16(TextBox2[9].Text);
b[3, 3] = Convert.ToInt16(TextBox2[10].Text);
b[3, 4] = Convert.ToInt16(TextBox2[11].Text);
b[4, 1] = Convert.ToInt16(TextBox2[12].Text);
b[4, 2] = Convert.ToInt16(TextBox2[13].Text);
b[4, 3] = Convert.ToInt16(TextBox2[14].Text);
b[4, 4] = Convert.ToInt16(TextBox2[15].Text);
Button3[0].Text = Convert.ToString(c[1, 1]);
Button3[1].Text = Convert.ToString(c[1, 2]);
Button3[2].Text = Convert.ToString(c[1, 3]);
Button3[3].Text = Convert.ToString(c[1, 4]);
Button3[4].Text = Convert.ToString(c[2, 1]);
Button3[5].Text = Convert.ToString(c[2, 2]);
Button3[6].Text = Convert.ToString(c[2, 3]);
Button3[7].Text = Convert.ToString(c[2, 4]);
Button3[8].Text = Convert.ToString(c[3, 1]);
Button3[9].Text = Convert.ToString(c[3, 2]);
Button3[10].Text = Convert.ToString(c[3, 3]);
Button3[11].Text = Convert.ToString(c[3, 4]);
Button3[12].Text = Convert.ToString(c[4, 1]);
Button3[13].Text = Convert.ToString(c[4, 2]);
Button3[14].Text = Convert.ToString(c[4, 3]);
Button3[15].Text = Convert.ToString(c[4, 4]);
}
}
}
}
}
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[] TextBox1;
System.Windows.Forms.TextBox[] TextBox2;
System.Windows.Forms.Button[] Button3;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
TextBox1 = new System.Windows.Forms.TextBox[16];
TextBox2 = new System.Windows.Forms.TextBox[16];
Button3 = new System.Windows.Forms.Button[16];
for (int d = 0; d < 16; d++)
{
TextBox1[d] = new TextBox();
this.Controls.Add(TextBox1[d]);
if (d <= 3)
TextBox1[d].Location = new System.Drawing.Point(10 + d * 100, 10);
else if (d > 3 && d <= 7)
TextBox1[d].Location = new System.Drawing.Point(10 + (d - 4) * 100, 40);
else if (d > 7 && d <= 11)
TextBox1[d].Location = new System.Drawing.Point(10 + (d - 8) * 100, 70);
else if (d > 11 && d <= 16)
TextBox1[d].Location = new System.Drawing.Point(10 + (d - 12) * 100, 100);
}
for (int f = 0; f < 16; f++)
{
TextBox2[f] = new TextBox();
this.Controls.Add(TextBox2[f]);
if (f <= 3)
TextBox2[f].Location = new System.Drawing.Point(10 + f * 100, 10 + 130);
else if (f > 3 && f <= 7)
TextBox2[f].Location = new System.Drawing.Point(10 + (f - 4) * 100, 40 + 130);
else if (f > 7 && f <= 11)
TextBox2[f].Location = new System.Drawing.Point(10 + (f - 8) * 100, 70 + 130);
else if (f > 11 && f <= 16)
TextBox2[f].Location = new System.Drawing.Point(10 + (f - 12) * 100, 100 + 130);
}
for (int g = 0; g < 16; g++)
{
Button3[g] = new Button();
this.Controls.Add(Button3[g]);
if (g <= 3)
Button3[g].Location = new System.Drawing.Point(10 + g * 80, 10 + 130 + 130);
else if (g > 3 && g <= 7)
Button3[g].Location = new System.Drawing.Point(10 + (g - 4) * 80, 40 + 130 + 130);
else if (g > 7 && g <= 11)
Button3[g].Location = new System.Drawing.Point(10 + (g - 8) * 80, 70 + 130 + 130);
else if (g > 11 && g <= 16)
Button3[g].Location = new System.Drawing.Point(10 + (g - 12) * 80, 100 + 130 + 130);
}
}
private void button2_Click(object sender, EventArgs e)
{
int[,] a = new int[5, 5];
int[,] b = new int[5, 5];
int[,] c = new int[5, 5];
int m, n;
m = 5;
n = 5;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < m; k++)
{
c[i, j] = c[i, j] + a[i, k] * b[k, j];
}
a[1, 1] = Convert.ToInt16(TextBox1[0].Text);
a[1, 2] = Convert.ToInt16(TextBox1[1].Text);
a[1, 3] = Convert.ToInt16(TextBox1[2].Text);
a[1, 4] = Convert.ToInt16(TextBox1[3].Text);
a[2, 1] = Convert.ToInt16(TextBox1[4].Text);
a[2, 2] = Convert.ToInt16(TextBox1[5].Text);
a[2, 3] = Convert.ToInt16(TextBox1[6].Text);
a[2, 4] = Convert.ToInt16(TextBox1[7].Text);
a[3, 1] = Convert.ToInt16(TextBox1[8].Text);
a[3, 2] = Convert.ToInt16(TextBox1[9].Text);
a[3, 3] = Convert.ToInt16(TextBox1[10].Text);
a[3, 4] = Convert.ToInt16(TextBox1[11].Text);
a[4, 1] = Convert.ToInt16(TextBox1[12].Text);
a[4, 2] = Convert.ToInt16(TextBox1[13].Text);
a[4, 3] = Convert.ToInt16(TextBox1[14].Text);
a[4, 4] = Convert.ToInt16(TextBox1[15].Text);
b[1, 1] = Convert.ToInt16(TextBox2[0].Text);
b[1, 2] = Convert.ToInt16(TextBox2[1].Text);
b[1, 3] = Convert.ToInt16(TextBox2[2].Text);
b[1, 4] = Convert.ToInt16(TextBox2[3].Text);
b[2, 1] = Convert.ToInt16(TextBox2[4].Text);
b[2, 2] = Convert.ToInt16(TextBox2[5].Text);
b[2, 3] = Convert.ToInt16(TextBox2[6].Text);
b[2, 4] = Convert.ToInt16(TextBox2[7].Text);
b[3, 1] = Convert.ToInt16(TextBox2[8].Text);
b[3, 2] = Convert.ToInt16(TextBox2[9].Text);
b[3, 3] = Convert.ToInt16(TextBox2[10].Text);
b[3, 4] = Convert.ToInt16(TextBox2[11].Text);
b[4, 1] = Convert.ToInt16(TextBox2[12].Text);
b[4, 2] = Convert.ToInt16(TextBox2[13].Text);
b[4, 3] = Convert.ToInt16(TextBox2[14].Text);
b[4, 4] = Convert.ToInt16(TextBox2[15].Text);
Button3[0].Text = Convert.ToString(c[1, 1]);
Button3[1].Text = Convert.ToString(c[1, 2]);
Button3[2].Text = Convert.ToString(c[1, 3]);
Button3[3].Text = Convert.ToString(c[1, 4]);
Button3[4].Text = Convert.ToString(c[2, 1]);
Button3[5].Text = Convert.ToString(c[2, 2]);
Button3[6].Text = Convert.ToString(c[2, 3]);
Button3[7].Text = Convert.ToString(c[2, 4]);
Button3[8].Text = Convert.ToString(c[3, 1]);
Button3[9].Text = Convert.ToString(c[3, 2]);
Button3[10].Text = Convert.ToString(c[3, 3]);
Button3[11].Text = Convert.ToString(c[3, 4]);
Button3[12].Text = Convert.ToString(c[4, 1]);
Button3[13].Text = Convert.ToString(c[4, 2]);
Button3[14].Text = Convert.ToString(c[4, 3]);
Button3[15].Text = Convert.ToString(c[4, 4]);
}
}
}
}
}
2010/1022 數字盤
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[] Button1;
System.Windows.Forms.TextBox[] TextBox1;
int[,] a = new int[4, 4];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Button1 = new System.Windows.Forms.Button[9];
TextBox1 = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
Button1[i] = new Button();
Button1[i].Click += new System.EventHandler(Button1_Click);
this.Controls.Add(Button1[i]);
if (i <= 2)
Button1[i].Location = new System.Drawing.Point(10 + i * 80, 10 + 100);
else if (i > 2 && i <= 5)
Button1[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Button1[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
for (int i = 0; i < 9; ++i)
{
TextBox1[i] = new TextBox();
this.Controls.Add(TextBox1[i]);
if (i <= 2)
TextBox1[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 2 && i <= 5)
TextBox1[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40);
else if (i > 5 && i <= 9)
TextBox1[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 70);
}
TextBox1[0].Text = "7";
TextBox1[1].Text = "2";
TextBox1[2].Text = "4";
TextBox1[3].Text = "5";
TextBox1[4].Text = "0";
TextBox1[5].Text = "6";
TextBox1[6].Text = "8";
TextBox1[7].Text = "3";
TextBox1[8].Text = "1";
}
public void Button1_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
MessageBox.Show(Convert.ToString(((Button)sender).Text));
}
private void button2_Click(object sender, EventArgs e)
{
//輸入
for (int j = 0; j < 9; j++)
{
if (j < 3)
{
a[1, j + 1] = Convert.ToInt16(TextBox1[j].Text);
}
else if (j >= 3 && j < 6)
{
a[2, j - 2] = Convert.ToInt16(TextBox1[j].Text);
}
else
{
a[3, j - 5] = Convert.ToInt16(TextBox1[j].Text);
}
//輸出
for (int i = 0; i < 9; i++)
{
if (i < 3)
{
Button1[i].Text = Convert.ToString(a[1, i + 1]);
}
else if (i >= 3 && i < 6)
{
Button1[i].Text = Convert.ToString(a[2, i - 2]);
}
else
{
Button1[i].Text = Convert.ToString(a[3, i - 5]);
}
}
}
}
}
}
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[] Button1;
System.Windows.Forms.TextBox[] TextBox1;
int[,] a = new int[4, 4];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Button1 = new System.Windows.Forms.Button[9];
TextBox1 = new System.Windows.Forms.TextBox[9];
for (int i = 0; i < 9; ++i)
{
Button1[i] = new Button();
Button1[i].Click += new System.EventHandler(Button1_Click);
this.Controls.Add(Button1[i]);
if (i <= 2)
Button1[i].Location = new System.Drawing.Point(10 + i * 80, 10 + 100);
else if (i > 2 && i <= 5)
Button1[i].Location = new System.Drawing.Point(10 + (i - 3) * 80, 40 + 100);
else if (i > 5 && i <= 9)
Button1[i].Location = new System.Drawing.Point(10 + (i - 6) * 80, 70 + 100);
}
for (int i = 0; i < 9; ++i)
{
TextBox1[i] = new TextBox();
this.Controls.Add(TextBox1[i]);
if (i <= 2)
TextBox1[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 2 && i <= 5)
TextBox1[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40);
else if (i > 5 && i <= 9)
TextBox1[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 70);
}
TextBox1[0].Text = "7";
TextBox1[1].Text = "2";
TextBox1[2].Text = "4";
TextBox1[3].Text = "5";
TextBox1[4].Text = "0";
TextBox1[5].Text = "6";
TextBox1[6].Text = "8";
TextBox1[7].Text = "3";
TextBox1[8].Text = "1";
}
public void Button1_Click(object sender, EventArgs e)
{
// System.Windows.Forms.MessageBox.Show("You have clicked button " +
// ((System.Windows.Forms.Button)sender).Tag.ToString());
MessageBox.Show(Convert.ToString(((Button)sender).Text));
}
private void button2_Click(object sender, EventArgs e)
{
//輸入
for (int j = 0; j < 9; j++)
{
if (j < 3)
{
a[1, j + 1] = Convert.ToInt16(TextBox1[j].Text);
}
else if (j >= 3 && j < 6)
{
a[2, j - 2] = Convert.ToInt16(TextBox1[j].Text);
}
else
{
a[3, j - 5] = Convert.ToInt16(TextBox1[j].Text);
}
//輸出
for (int i = 0; i < 9; i++)
{
if (i < 3)
{
Button1[i].Text = Convert.ToString(a[1, i + 1]);
}
else if (i >= 3 && i < 6)
{
Button1[i].Text = Convert.ToString(a[2, i - 2]);
}
else
{
Button1[i].Text = Convert.ToString(a[3, i - 5]);
}
}
}
}
}
}
2010年10月8日 星期五
10/8 作業3*3矩陣相乘
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
{
Form2 newform;
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int a=0, b=0, c;
String output;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a * b;
output = Convert.ToString(c);
textBox3.Text = output;
}
private void button2_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.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 WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int d, x, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w;
String output;
d = int.Parse(textBox9.Text);
x = int.Parse(textBox8.Text);
f = int.Parse(textBox7.Text);
g = int.Parse(textBox6.Text);
h = int.Parse(textBox5.Text);
i = int.Parse(textBox4.Text);
j = int.Parse(textBox3.Text);
k = int.Parse(textBox2.Text);
l = int.Parse(textBox1.Text);
m = int.Parse(textBox18.Text);
n = int.Parse(textBox17.Text);
o = int.Parse(textBox16.Text);
p = int.Parse(textBox15.Text);
q = int.Parse(textBox14.Text);
r = int.Parse(textBox13.Text);
s = int.Parse(textBox12.Text);
t = int.Parse(textBox11.Text);
u = int.Parse(textBox10.Text);
int[,] a = new int[4,4];
int[,] b = new int[4,4];
int[,] c = new int[4,4];
a[1, 1] = d;
a[1, 2] = x;
a[1, 3] = f;
a[2, 1] = g;
a[2, 2] = h;
a[2, 3] = i;
a[3, 1] = j;
a[3, 2] = k;
a[3, 3] = l;
b[1, 1] = m;
b[1, 2] = n;
b[1, 3] = o;
b[2, 1] = p;
b[2, 2] = q;
b[2, 3] = r;
b[3, 1] = s;
b[3, 2] = t;
b[3, 3] = u;
c[1, 1] = 0;
c[1, 2] = 0;
c[1, 3] = 0;
c[2, 1] = 0;
c[2, 2] = 0;
c[2, 3] = 0;
c[3, 1] = 0;
c[3, 2] = 0;
c[3, 3] = 0;
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 = Convert.ToString(c[1, 1]);
textBox20.Text = Convert.ToString(c[1, 2]);
textBox21.Text = Convert.ToString(c[1, 3]);
textBox22.Text = Convert.ToString(c[2, 1]);
textBox23.Text = Convert.ToString(c[2, 2]);
textBox24.Text = Convert.ToString(c[2, 3]);
textBox25.Text = Convert.ToString(c[3, 1]);
textBox26.Text = Convert.ToString(c[3, 2]);
textBox27.Text = Convert.ToString(c[3, 3]);
}
}
}
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
{
Form2 newform;
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int a=0, b=0, c;
String output;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = a * b;
output = Convert.ToString(c);
textBox3.Text = output;
}
private void button2_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.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 WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int d, x, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w;
String output;
d = int.Parse(textBox9.Text);
x = int.Parse(textBox8.Text);
f = int.Parse(textBox7.Text);
g = int.Parse(textBox6.Text);
h = int.Parse(textBox5.Text);
i = int.Parse(textBox4.Text);
j = int.Parse(textBox3.Text);
k = int.Parse(textBox2.Text);
l = int.Parse(textBox1.Text);
m = int.Parse(textBox18.Text);
n = int.Parse(textBox17.Text);
o = int.Parse(textBox16.Text);
p = int.Parse(textBox15.Text);
q = int.Parse(textBox14.Text);
r = int.Parse(textBox13.Text);
s = int.Parse(textBox12.Text);
t = int.Parse(textBox11.Text);
u = int.Parse(textBox10.Text);
int[,] a = new int[4,4];
int[,] b = new int[4,4];
int[,] c = new int[4,4];
a[1, 1] = d;
a[1, 2] = x;
a[1, 3] = f;
a[2, 1] = g;
a[2, 2] = h;
a[2, 3] = i;
a[3, 1] = j;
a[3, 2] = k;
a[3, 3] = l;
b[1, 1] = m;
b[1, 2] = n;
b[1, 3] = o;
b[2, 1] = p;
b[2, 2] = q;
b[2, 3] = r;
b[3, 1] = s;
b[3, 2] = t;
b[3, 3] = u;
c[1, 1] = 0;
c[1, 2] = 0;
c[1, 3] = 0;
c[2, 1] = 0;
c[2, 2] = 0;
c[2, 3] = 0;
c[3, 1] = 0;
c[3, 2] = 0;
c[3, 3] = 0;
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 = Convert.ToString(c[1, 1]);
textBox20.Text = Convert.ToString(c[1, 2]);
textBox21.Text = Convert.ToString(c[1, 3]);
textBox22.Text = Convert.ToString(c[2, 1]);
textBox23.Text = Convert.ToString(c[2, 2]);
textBox24.Text = Convert.ToString(c[2, 3]);
textBox25.Text = Convert.ToString(c[3, 1]);
textBox26.Text = Convert.ToString(c[3, 2]);
textBox27.Text = Convert.ToString(c[3, 3]);
}
}
}
2010年10月1日 星期五
C# listbox 九九乘法表 10/1
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
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int a1, an, n, d, sn;
a1 = int.Parse(textBox1.Text);
d = int.Parse(textBox2.Text);
n = int.Parse(textBox3.Text);
an = a1 + (n - 1) * d;
sn = n / 2 * (2 * a1 + (n - 1) * d);
textBox4.Text = "" + an;
textBox5.Text = "" + sn;
}
private void button2_Click(object sender, EventArgs e)
{
int[,] arr1 = new int[10, 10];
int[,] arr2 = new int[10, 10];
int[,] arr3 = new int[10, 10];
int[,] arr4 = new int[10, 10];
int[,] arr5 = new int[10, 10];
int[,] arr6 = new int[10, 10];
int[,] arr7 = new int[10, 10];
int[,] arr8 = new int[10, 10];
int[,] arr9 = new int[10, 10];
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
arr1[i, j] = 1 * j;
arr2[i, j] = 2 * j;
arr3[i, j] = 3 * j;
arr4[i, j] = 4 * j;
arr5[i, j] = 5 * j;
arr6[i, j] = 6 * j;
arr7[i, j] = 7 * j;
arr8[i, j] = 8 * j;
arr9[i, j] = 9 * j;
}
}
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
Console.WriteLine(+i + "*" + j + "=" + arr1[i, j]);
listBox1.Items.Add(+1 + "*" + j + "=" + arr1[i, j]
+ " " + 2 + "*" + j + "=" + arr2[i, j]
+ " " + 3 + "*" + j + "=" + arr3[i, j]
+ " " + 4 + "*" + j + "=" + arr4[i, j]
+ " " + 5 + "*" + j + "=" + arr5[i, j]
+ " " + 6 + "*" + j + "=" + arr6[i, j]
+ " " + 7 + "*" + j + "=" + arr7[i, j]
+ " " + 8 + "*" + j + "=" + arr8[i, j]
+ " " + 9 + "*" + j + "=" + arr9[i, j]);
}
}
}
}
}
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
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int a1, an, n, d, sn;
a1 = int.Parse(textBox1.Text);
d = int.Parse(textBox2.Text);
n = int.Parse(textBox3.Text);
an = a1 + (n - 1) * d;
sn = n / 2 * (2 * a1 + (n - 1) * d);
textBox4.Text = "" + an;
textBox5.Text = "" + sn;
}
private void button2_Click(object sender, EventArgs e)
{
int[,] arr1 = new int[10, 10];
int[,] arr2 = new int[10, 10];
int[,] arr3 = new int[10, 10];
int[,] arr4 = new int[10, 10];
int[,] arr5 = new int[10, 10];
int[,] arr6 = new int[10, 10];
int[,] arr7 = new int[10, 10];
int[,] arr8 = new int[10, 10];
int[,] arr9 = new int[10, 10];
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
arr1[i, j] = 1 * j;
arr2[i, j] = 2 * j;
arr3[i, j] = 3 * j;
arr4[i, j] = 4 * j;
arr5[i, j] = 5 * j;
arr6[i, j] = 6 * j;
arr7[i, j] = 7 * j;
arr8[i, j] = 8 * j;
arr9[i, j] = 9 * j;
}
}
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
Console.WriteLine(+i + "*" + j + "=" + arr1[i, j]);
listBox1.Items.Add(+1 + "*" + j + "=" + arr1[i, j]
+ " " + 2 + "*" + j + "=" + arr2[i, j]
+ " " + 3 + "*" + j + "=" + arr3[i, j]
+ " " + 4 + "*" + j + "=" + arr4[i, j]
+ " " + 5 + "*" + j + "=" + arr5[i, j]
+ " " + 6 + "*" + j + "=" + arr6[i, j]
+ " " + 7 + "*" + j + "=" + arr7[i, j]
+ " " + 8 + "*" + j + "=" + arr8[i, j]
+ " " + 9 + "*" + j + "=" + arr9[i, j]);
}
}
}
}
}
訂閱:
文章 (Atom)