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;
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 i = 0; i < 9; ++i)
{
TextBoxs[i] = new TextBox();
this.Controls.Add(TextBoxs[i]);
if (i <= 2)
TextBoxs[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 2 && i <= 5)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40);
else if (i > 5 && i <= 9)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 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 i = 0; i < 9; i++)
{
if (Buttons[i].Text == no)
bno = i;
}
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;
}
else if (Buttons[3].Text == "0")
{
String temp;
temp = Buttons[3].Text;
Buttons[3].Text = Buttons[0].Text;
Buttons[0].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
case 1:
if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].Text = Buttons[1].Text;
Buttons[1].Text = temp;
}
else if (Buttons[0].Text == "0")
{
String temp;
temp = Buttons[0].Text;
Buttons[0].Text = Buttons[1].Text;
Buttons[1].Text = temp;
}
else if (Buttons[2].Text == "0")
{
String temp;
temp = Buttons[2].Text;
Buttons[2].Text = Buttons[1].Text;
Buttons[1].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
case 2:
if (Buttons[1].Text == "0")
{
String temp;
temp = Buttons[1].Text;
Buttons[1].Text = Buttons[2].Text;
Buttons[2].Text = temp;
}
else if (Buttons[5].Text == "0")
{
String temp;
temp = Buttons[5].Text;
Buttons[5].Text = Buttons[2].Text;
Buttons[2].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
case 3:
if (Buttons[0].Text == "0")
{
String temp;
temp = Buttons[0].Text;
Buttons[0].Text = Buttons[3].Text;
Buttons[3].Text = temp;
}
else if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].Text = Buttons[3].Text;
Buttons[3].Text = temp;
}
else if (Buttons[6].Text == "0")
{
String temp;
temp = Buttons[6].Text;
Buttons[6].Text = Buttons[3].Text;
Buttons[3].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
case 4:
if (Buttons[1].Text == "0")
{
String temp;
temp = Buttons[1].Text;
Buttons[1].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
else if (Buttons[3].Text == "0")
{
String temp;
temp = Buttons[3].Text;
Buttons[3].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
else if (Buttons[5].Text == "0")
{
String temp;
temp = Buttons[5].Text;
Buttons[5].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
else if (Buttons[7].Text == "0")
{
String temp;
temp = Buttons[7].Text;
Buttons[7].Text = Buttons[4].Text;
Buttons[4].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
case 5:
if (Buttons[2].Text == "0")
{
String temp;
temp = Buttons[2].Text;
Buttons[2].Text = Buttons[5].Text;
Buttons[5].Text = temp;
}
else if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].Text = Buttons[5].Text;
Buttons[5].Text = temp;
}
else if (Buttons[8].Text == "0")
{
String temp;
temp = Buttons[8].Text;
Buttons[8].Text = Buttons[5].Text;
Buttons[5].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
case 6:
if (Buttons[3].Text == "0")
{
String temp;
temp = Buttons[3].Text;
Buttons[3].Text = Buttons[6].Text;
Buttons[6].Text = temp;
}
else if (Buttons[7].Text == "0")
{
String temp;
temp = Buttons[7].Text;
Buttons[7].Text = Buttons[6].Text;
Buttons[6].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
case 7:
if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].Text = Buttons[7].Text;
Buttons[7].Text = temp;
}
else if (Buttons[6].Text == "0")
{
String temp;
temp = Buttons[6].Text;
Buttons[6].Text = Buttons[7].Text;
Buttons[7].Text = temp;
}
else if (Buttons[8].Text == "0")
{
String temp;
temp = Buttons[8].Text;
Buttons[8].Text = Buttons[7].Text;
Buttons[7].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
case 8:
if (Buttons[5].Text == "0")
{
String temp;
temp = Buttons[5].Text;
Buttons[5].Text = Buttons[8].Text;
Buttons[8].Text = temp;
}
else if (Buttons[7].Text == "0")
{
String temp;
temp = Buttons[7].Text;
Buttons[7].Text = Buttons[8].Text;
Buttons[8].Text = temp;
}
else
MessageBox.Show("不可以換");
break;
}
}
private void button1_Click_1(object sender, EventArgs e)
{
//讀入 input
a[1, 1] = Convert.ToInt16(TextBoxs[0].Text);
a[1, 2] = Convert.ToInt16(TextBoxs[1].Text);
a[1, 3] = Convert.ToInt16(TextBoxs[2].Text);
a[2, 1] = Convert.ToInt16(TextBoxs[3].Text);
a[2, 2] = Convert.ToInt16(TextBoxs[4].Text);
a[2, 3] = Convert.ToInt16(TextBoxs[5].Text);
a[3, 1] = Convert.ToInt16(TextBoxs[6].Text);
a[3, 2] = Convert.ToInt16(TextBoxs[7].Text);
a[3, 3] = Convert.ToInt16(TextBoxs[8].Text);
//輸出 output
for (int i = 0; i < 9; i++)
if (i < 3)
{
Buttons[i].Text = Convert.ToString(a[1, i + 1]);
}
else if (i >= 3 && i < 6)
{
Buttons[i].Text = Convert.ToString(a[2, (i - 3) + 1]);
}
else if (i >= 6 && i < 9)
{
Buttons[i].Text = Convert.ToString(a[3, (i - 6) + 1]);
}
}
}
}
2010年10月29日 星期五
2010年10月22日 星期五
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.Button[] Buttons;
System.Windows.Forms.TextBox[] TextBoxs;
int[,] a = new int[4, 4];
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 i = 0; i < 9; ++i)
{
TextBoxs[i] = new TextBox();
this.Controls.Add(TextBoxs[i]);
if (i <= 2)
TextBoxs[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 2 && i <= 5)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40);
else if (i > 5 && i <= 9)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 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)
{
MessageBox.Show("按三小");
}
private void button1_Click(object sender, EventArgs e)
{
//讀入 input
a[1, 1] = Convert.ToInt16(TextBoxs[0].Text);
a[1, 2] = Convert.ToInt16(TextBoxs[1].Text);
a[1, 3] = Convert.ToInt16(TextBoxs[2].Text);
a[2, 1] = Convert.ToInt16(TextBoxs[3].Text);
a[2, 2] = Convert.ToInt16(TextBoxs[4].Text);
a[2, 3] = Convert.ToInt16(TextBoxs[5].Text);
a[3, 1] = Convert.ToInt16(TextBoxs[6].Text);
a[3, 2] = Convert.ToInt16(TextBoxs[7].Text);
a[3, 3] = Convert.ToInt16(TextBoxs[8].Text);
//輸出 output
for (int i = 0; i < 9; i++)
if(i<3)
{
Buttons[i].Text = Convert.ToString(a[1, i+1]);
}
else if (i>=3 && i<6)
{
Buttons[i].Text = Convert.ToString(a[2, (i-3) + 1]);
}
else if (i>=6 && i<9)
{
Buttons[i].Text = Convert.ToString(a[3, (i-6) + 1]);
}
}
}
}
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];
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 i = 0; i < 9; ++i)
{
TextBoxs[i] = new TextBox();
this.Controls.Add(TextBoxs[i]);
if (i <= 2)
TextBoxs[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 2 && i <= 5)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 100, 40);
else if (i > 5 && i <= 9)
TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 100, 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)
{
MessageBox.Show("按三小");
}
private void button1_Click(object sender, EventArgs e)
{
//讀入 input
a[1, 1] = Convert.ToInt16(TextBoxs[0].Text);
a[1, 2] = Convert.ToInt16(TextBoxs[1].Text);
a[1, 3] = Convert.ToInt16(TextBoxs[2].Text);
a[2, 1] = Convert.ToInt16(TextBoxs[3].Text);
a[2, 2] = Convert.ToInt16(TextBoxs[4].Text);
a[2, 3] = Convert.ToInt16(TextBoxs[5].Text);
a[3, 1] = Convert.ToInt16(TextBoxs[6].Text);
a[3, 2] = Convert.ToInt16(TextBoxs[7].Text);
a[3, 3] = Convert.ToInt16(TextBoxs[8].Text);
//輸出 output
for (int i = 0; i < 9; i++)
if(i<3)
{
Buttons[i].Text = Convert.ToString(a[1, i+1]);
}
else if (i>=3 && i<6)
{
Buttons[i].Text = Convert.ToString(a[2, (i-3) + 1]);
}
else if (i>=6 && i<9)
{
Buttons[i].Text = Convert.ToString(a[3, (i-6) + 1]);
}
}
}
}
2010年10月15日 星期五
10-15 作業
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
{
System.Windows.Forms.TextBox[] textBox;
System.Windows.Forms.TextBox[] textBoxs;
System.Windows.Forms.Button[] Buttons;
int[,] a = new int[5, 5];
int[,] b = new int[5, 5];
int[,] c = new int[5, 5];
int m, n;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textBox[i] = new TextBox();
this.Controls.Add(textBox[i]);
if (i <= 3)
textBox[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 3 && i <= 7)
textBox[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 40);
else if (i > 7 && i <= 11)
textBox[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 70);
else if (i > 11 && i <= 15)
textBox[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 100);
}
textBoxs = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textBoxs[i] = new TextBox();
this.Controls.Add(textBoxs[i]);
if (i <= 3)
textBoxs[i].Location = new System.Drawing.Point(10 + i * 100+500, 10);
else if (i > 3 && i <= 7)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 4) * 100 + 500, 40);
else if (i > 7 && i <= 11)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 8) * 100 + 500, 70);
else if (i > 11 && i <= 15)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 12) * 100 + 500, 100);
}
Buttons = new System.Windows.Forms.Button[16];
for (int i = 0; i < 16; i++)
{
Buttons[i] = new Button();
this.Controls.Add(Buttons[i]);
if (i <= 3)
Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 10 + 200);
else if (i > 3 && i <= 7)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 4) * 80, 40 + 200);
else if (i > 7 && i <= 11)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 8) * 80, 70 + 200);
else if (i > 11 && i <= 15)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 12) * 80, 100 + 200);
}
textBox[0].Text = "1";
textBox[1].Text = "0";
textBox[2].Text = "0";
textBox[3].Text = "0";
textBox[4].Text = "0";
textBox[5].Text = "1";
textBox[6].Text = "0";
textBox[7].Text = "0";
textBox[8].Text = "0";
textBox[9].Text = "0";
textBox[10].Text = "1";
textBox[11].Text = "0";
textBox[12].Text = "0";
textBox[13].Text = "0";
textBox[14].Text = "0";
textBox[15].Text = "1";
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";
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
{
for (int k = 1; k < m; k++)
{
c[i, j] = c[i, j] + a[i, k] * b[k, j];
}
}
}
//input
a[1, 1] = Convert.ToInt16(textBox[0].Text);
a[1, 2] = Convert.ToInt16(textBox[1].Text);
a[1, 3] = Convert.ToInt16(textBox[2].Text);
a[1, 4] = Convert.ToInt16(textBox[3].Text);
a[2, 1] = Convert.ToInt16(textBox[4].Text);
a[2, 2] = Convert.ToInt16(textBox[5].Text);
a[2, 3] = Convert.ToInt16(textBox[6].Text);
a[2, 4] = Convert.ToInt16(textBox[7].Text);
a[3, 1] = Convert.ToInt16(textBox[8].Text);
a[3, 2] = Convert.ToInt16(textBox[9].Text);
a[3, 3] = Convert.ToInt16(textBox[10].Text);
a[3, 4] = Convert.ToInt16(textBox[11].Text);
a[4, 1] = Convert.ToInt16(textBox[12].Text);
a[4, 2] = Convert.ToInt16(textBox[13].Text);
a[4, 3] = Convert.ToInt16(textBox[14].Text);
a[4, 4] = Convert.ToInt16(textBox[15].Text);
//output
for (int i = 0; i < 16; ++i)
if (i < 4)
{
Buttons[i].Text = Convert.ToString(a[1, i + 1]);
}
else if (i >= 4 && i < 8)
{
Buttons[i].Text = Convert.ToString(a[2, (i - 4) + 1]);
}
else if (i >= 8 && i < 12)
{
Buttons[i].Text = Convert.ToString(a[3, (i - 4 * 2) + 1]);
}
else
{
Buttons[i].Text = Convert.ToString(a[4, (i - 4 * 3) + 1]);
}
}
}
}
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
{
System.Windows.Forms.TextBox[] textBox;
System.Windows.Forms.TextBox[] textBoxs;
System.Windows.Forms.Button[] Buttons;
int[,] a = new int[5, 5];
int[,] b = new int[5, 5];
int[,] c = new int[5, 5];
int m, n;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textBox[i] = new TextBox();
this.Controls.Add(textBox[i]);
if (i <= 3)
textBox[i].Location = new System.Drawing.Point(10 + i * 100, 10);
else if (i > 3 && i <= 7)
textBox[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 40);
else if (i > 7 && i <= 11)
textBox[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 70);
else if (i > 11 && i <= 15)
textBox[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 100);
}
textBoxs = new System.Windows.Forms.TextBox[16];
for (int i = 0; i < 16; i++)
{
textBoxs[i] = new TextBox();
this.Controls.Add(textBoxs[i]);
if (i <= 3)
textBoxs[i].Location = new System.Drawing.Point(10 + i * 100+500, 10);
else if (i > 3 && i <= 7)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 4) * 100 + 500, 40);
else if (i > 7 && i <= 11)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 8) * 100 + 500, 70);
else if (i > 11 && i <= 15)
textBoxs[i].Location = new System.Drawing.Point(10 + (i - 12) * 100 + 500, 100);
}
Buttons = new System.Windows.Forms.Button[16];
for (int i = 0; i < 16; i++)
{
Buttons[i] = new Button();
this.Controls.Add(Buttons[i]);
if (i <= 3)
Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 10 + 200);
else if (i > 3 && i <= 7)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 4) * 80, 40 + 200);
else if (i > 7 && i <= 11)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 8) * 80, 70 + 200);
else if (i > 11 && i <= 15)
Buttons[i].Location = new System.Drawing.Point(10 + (i - 12) * 80, 100 + 200);
}
textBox[0].Text = "1";
textBox[1].Text = "0";
textBox[2].Text = "0";
textBox[3].Text = "0";
textBox[4].Text = "0";
textBox[5].Text = "1";
textBox[6].Text = "0";
textBox[7].Text = "0";
textBox[8].Text = "0";
textBox[9].Text = "0";
textBox[10].Text = "1";
textBox[11].Text = "0";
textBox[12].Text = "0";
textBox[13].Text = "0";
textBox[14].Text = "0";
textBox[15].Text = "1";
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";
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
{
for (int k = 1; k < m; k++)
{
c[i, j] = c[i, j] + a[i, k] * b[k, j];
}
}
}
//input
a[1, 1] = Convert.ToInt16(textBox[0].Text);
a[1, 2] = Convert.ToInt16(textBox[1].Text);
a[1, 3] = Convert.ToInt16(textBox[2].Text);
a[1, 4] = Convert.ToInt16(textBox[3].Text);
a[2, 1] = Convert.ToInt16(textBox[4].Text);
a[2, 2] = Convert.ToInt16(textBox[5].Text);
a[2, 3] = Convert.ToInt16(textBox[6].Text);
a[2, 4] = Convert.ToInt16(textBox[7].Text);
a[3, 1] = Convert.ToInt16(textBox[8].Text);
a[3, 2] = Convert.ToInt16(textBox[9].Text);
a[3, 3] = Convert.ToInt16(textBox[10].Text);
a[3, 4] = Convert.ToInt16(textBox[11].Text);
a[4, 1] = Convert.ToInt16(textBox[12].Text);
a[4, 2] = Convert.ToInt16(textBox[13].Text);
a[4, 3] = Convert.ToInt16(textBox[14].Text);
a[4, 4] = Convert.ToInt16(textBox[15].Text);
//output
for (int i = 0; i < 16; ++i)
if (i < 4)
{
Buttons[i].Text = Convert.ToString(a[1, i + 1]);
}
else if (i >= 4 && i < 8)
{
Buttons[i].Text = Convert.ToString(a[2, (i - 4) + 1]);
}
else if (i >= 8 && i < 12)
{
Buttons[i].Text = Convert.ToString(a[3, (i - 4 * 2) + 1]);
}
else
{
Buttons[i].Text = Convert.ToString(a[4, (i - 4 * 3) + 1]);
}
}
}
}
2010年10月1日 星期五
10-01 作業listbox 產生 開新視窗
Form1.cs
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 button1_Click(object sender, EventArgs e)
{
//宣告
int a1, an, d, n, sn;
//輸入
a1 = int.Parse(textBox1.Text);
d = int.Parse(textBox2.Text);
n = int.Parse(textBox3.Text);
//計算
an = a1 + (n - 1) * d;
sn = n * (a1 + an) / 2;
//Post
textBox4.Text = "" + an;
textBox5.Text = "" + sn;
}
private void button2_Click(object sender, EventArgs e)
{
int sum = 0;
int[,] arr1 = new int[99, 99];
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
sum = i * j;
arr1[i, j] = sum;
}
}
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
Console.WriteLine("" + i + "*" + "" + j + "=" + arr1[i, j]);
Console.WriteLine("i=" + i + "j= " + j);
listBox1.Items.Add("" + i + "*" + "" + j + "=" + arr1[i, j]);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.Show();
}
}
}
==========================================================================
Form2.cs
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 button3_Click(object sender, EventArgs e)
{
int sum = 0;
int[,] arr1 = new int[99, 99];
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
sum = i * j;
arr1[i, j] = sum;
}
}
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
Console.WriteLine("" + i + "*" + "" + j + "=" + arr1[i, j]);
Console.WriteLine("i=" + i + "j= " + j);
listBox1.Items.Add("" + i + "*" + "" + j + "=" + arr1[i, j]);
}
}
}
}
}
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 button1_Click(object sender, EventArgs e)
{
//宣告
int a1, an, d, n, sn;
//輸入
a1 = int.Parse(textBox1.Text);
d = int.Parse(textBox2.Text);
n = int.Parse(textBox3.Text);
//計算
an = a1 + (n - 1) * d;
sn = n * (a1 + an) / 2;
//Post
textBox4.Text = "" + an;
textBox5.Text = "" + sn;
}
private void button2_Click(object sender, EventArgs e)
{
int sum = 0;
int[,] arr1 = new int[99, 99];
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
sum = i * j;
arr1[i, j] = sum;
}
}
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
Console.WriteLine("" + i + "*" + "" + j + "=" + arr1[i, j]);
Console.WriteLine("i=" + i + "j= " + j);
listBox1.Items.Add("" + i + "*" + "" + j + "=" + arr1[i, j]);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
newform = new Form2();
newform.Show();
}
}
}
==========================================================================
Form2.cs
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 button3_Click(object sender, EventArgs e)
{
int sum = 0;
int[,] arr1 = new int[99, 99];
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
sum = i * j;
arr1[i, j] = sum;
}
}
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
Console.WriteLine("" + i + "*" + "" + j + "=" + arr1[i, j]);
Console.WriteLine("i=" + i + "j= " + j);
listBox1.Items.Add("" + i + "*" + "" + j + "=" + arr1[i, j]);
}
}
}
}
}
訂閱:
文章 (Atom)