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]);
}
}
}
}
}
}
沒有留言:
張貼留言