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 bno;
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)
{
// 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;
}
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[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].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[0].Text == "0")
{
String temp;
temp = Buttons[0].Text;
Buttons[0].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[0].Text == "0")
{
String temp;
temp = Buttons[0].Text;
Buttons[0].Text = Buttons[3].Text;
Buttons[3].Text = temp;
}
if (Buttons[4].Text == "0")
{
String temp;
temp = Buttons[4].Text;
Buttons[4].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[].Text;
Buttons[7].Text = Buttons[8].Text;
Buttons[8].Text = temp;
}
break;
}
}
private void button1_Click(object sender, EventArgs e)
{
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);
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
{
Buttons[i].Text = Convert.ToString(a[3, (i - 3 * 2) + 1]);
}
}
}
}
}
2010年10月29日 星期五
2010年10月8日 星期五
第4次作業
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 a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0, a9 = 0;
int b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0, b7 = 0, b8 = 0, b9 = 0;
int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0;
int[,] a = new int[3, 3];
int[,] b = new int[3, 3];
int[,] c = new int[3, 3];
String output;
a1 = int.Parse(textBox1.Text);
a2 = int.Parse(textBox2.Text);
a3 = int.Parse(textBox3.Text);
a4 = int.Parse(textBox4.Text);
a5 = int.Parse(textBox5.Text);
a6 = int.Parse(textBox6.Text);
a7 = int.Parse(textBox7.Text);
a8 = int.Parse(textBox8.Text);
a9 = int.Parse(textBox.Text);
b1 = int.Parse(textBox10.Text);
b2 = int.Parse(textBox11.Text);
b3 = int.Parse(textBox12.Text);
b4 = int.Parse(textBox13.Text);
b5 = int.Parse(textBox14.Text);
b6 = int.Parse(textBox15.Text);
b7 = int.Parse(textBox16.Text);
b8 = int.Parse(textBox17.Text);
b9 = int.Parse(textBox18.Text);
c1 = a1 * b1 + a4 * b2 + a7 * b3;
c2 = a2 * b1 + a5 * b2 + a8 * b3;
c3 = a3 * b1 + a6 * b2 + a9 * b3;
c4 = a1 * b4 + a4 * b5 + a7 * b6;
c5 = a2 * b4 + a5 * b5 + a8 * b6;
c6 = a3 * b4 + a6 * b5 + a9 * b6;
c7 = a1 * b7 + a4 * b8 + a7 * b9;
c8 = a2 * b7 + a5 * b8 + a8 * b9;
c9 = a3 * b7 + a6 * b8 + a9 * b9;
output = Convert.ToString(c1);
textBox19.Text = Convert.ToString(c1);
output = Convert.ToString(c2);
textBox20.Text = Convert.ToString(c2);
output = Convert.ToString(c3);
textBox21.Text = Convert.ToString(c3);
output = Convert.ToString(c4);
textBox22.Text = Convert.ToString(c4);
output = Convert.ToString(c5);
textBox23.Text = Convert.ToString(c5);
output = Convert.ToString(c6);
textBox24.Text = Convert.ToString(c6);
output = Convert.ToString(c7);
textBox25.Text = Convert.ToString(c7);
output = Convert.ToString(c8);
textBox26.Text = Convert.ToString(c8);
output = Convert.ToString(c9);
textBox27.Text = Convert.ToString(c9);
}
}
}
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 a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0, a9 = 0;
int b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0, b7 = 0, b8 = 0, b9 = 0;
int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0;
int[,] a = new int[3, 3];
int[,] b = new int[3, 3];
int[,] c = new int[3, 3];
String output;
a1 = int.Parse(textBox1.Text);
a2 = int.Parse(textBox2.Text);
a3 = int.Parse(textBox3.Text);
a4 = int.Parse(textBox4.Text);
a5 = int.Parse(textBox5.Text);
a6 = int.Parse(textBox6.Text);
a7 = int.Parse(textBox7.Text);
a8 = int.Parse(textBox8.Text);
a9 = int.Parse(textBox.Text);
b1 = int.Parse(textBox10.Text);
b2 = int.Parse(textBox11.Text);
b3 = int.Parse(textBox12.Text);
b4 = int.Parse(textBox13.Text);
b5 = int.Parse(textBox14.Text);
b6 = int.Parse(textBox15.Text);
b7 = int.Parse(textBox16.Text);
b8 = int.Parse(textBox17.Text);
b9 = int.Parse(textBox18.Text);
c1 = a1 * b1 + a4 * b2 + a7 * b3;
c2 = a2 * b1 + a5 * b2 + a8 * b3;
c3 = a3 * b1 + a6 * b2 + a9 * b3;
c4 = a1 * b4 + a4 * b5 + a7 * b6;
c5 = a2 * b4 + a5 * b5 + a8 * b6;
c6 = a3 * b4 + a6 * b5 + a9 * b6;
c7 = a1 * b7 + a4 * b8 + a7 * b9;
c8 = a2 * b7 + a5 * b8 + a8 * b9;
c9 = a3 * b7 + a6 * b8 + a9 * b9;
output = Convert.ToString(c1);
textBox19.Text = Convert.ToString(c1);
output = Convert.ToString(c2);
textBox20.Text = Convert.ToString(c2);
output = Convert.ToString(c3);
textBox21.Text = Convert.ToString(c3);
output = Convert.ToString(c4);
textBox22.Text = Convert.ToString(c4);
output = Convert.ToString(c5);
textBox23.Text = Convert.ToString(c5);
output = Convert.ToString(c6);
textBox24.Text = Convert.ToString(c6);
output = Convert.ToString(c7);
textBox25.Text = Convert.ToString(c7);
output = Convert.ToString(c8);
textBox26.Text = Convert.ToString(c8);
output = Convert.ToString(c9);
textBox27.Text = Convert.ToString(c9);
}
}
}
2010年10月1日 星期五
第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 button1_Click(object sender, EventArgs e)
{
int a1,d,an,n,sn;
a1 = int.Parse(textBox1.Text);
d = int.Parse(textBox3.Text);
n = int.Parse(textBox2.Text);
an = a1+(n-1)*d;
sn = (a1 + an) * n / 2;
textBox4.Text = ""+an ;
textBox5.Text = "" + sn;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label6_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, System.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 listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
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=12 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");
}
}
}
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,d,an,n,sn;
a1 = int.Parse(textBox1.Text);
d = int.Parse(textBox3.Text);
n = int.Parse(textBox2.Text);
an = a1+(n-1)*d;
sn = (a1 + an) * n / 2;
textBox4.Text = ""+an ;
textBox5.Text = "" + sn;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label6_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, System.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 listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
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=12 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)