2010年10月22日 星期五

99/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.Button[] Buttons;
        System.Windows.Forms.TextBox[] textBoxes;
        System.Windows.Forms.TextBox[] TextBoxe;
        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)
        {
            textBoxes = new System.Windows.Forms.TextBox[16];
            for (int i = 0; i < 16; i++)
            {
                textBoxes[i] = new TextBox();
                this.Controls.Add(textBoxes[i]);
                if (i <= 3)
                    textBoxes[i].Location = new System.Drawing.Point(10 + i * 100, 10);
                else if (i > 3 && i <= 7)
                    textBoxes[i].Location = new System.Drawing.Point(10 + (i - 4) * 100, 40);
                else if (i > 7 && i <= 11)
                    textBoxes[i].Location = new System.Drawing.Point(10 + (i - 8) * 100, 70);
                else if (i > 11 && i <= 15)
                    textBoxes[i].Location = new System.Drawing.Point(10 + (i - 12) * 100, 100);
            }
            TextBoxe = new System.Windows.Forms.TextBox[16];
            for (int i = 0; i < 16; i++)
            {
                TextBoxe[i] = new TextBox();
                this.Controls.Add(TextBoxe[i]);
                if (i <= 3)
                    TextBoxe[i].Location = new System.Drawing.Point(500 + i * 100, 10);
                else if (i > 3 && i <= 7)
                    TextBoxe[i].Location = new System.Drawing.Point(500 + (i - 4) * 100, 40);
                else if (i > 7 && i <= 11)
                    TextBoxe[i].Location = new System.Drawing.Point(500 + (i - 8) * 100, 70);
                else if (i > 11 && i <= 15)
                    TextBoxe[i].Location = new System.Drawing.Point(500 + (i - 12) * 100, 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, 200);
                else if (i > 3 && i <= 7)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 4) * 80, 240);
                else if (i > 7 && i <= 11)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 8) * 80, 270);
                else if (i > 11 && i <= 15)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 12) * 80, 300);
            }
            TextBoxe[0].Text = "1";
            TextBoxe[1].Text = "0";
            TextBoxe[2].Text = "0";
            TextBoxe[3].Text = "0";
            TextBoxe[4].Text = "0";
            TextBoxe[5].Text = "1";
            TextBoxe[6].Text = "0";
            TextBoxe[7].Text = "0";
            TextBoxe[8].Text = "0";
            TextBoxe[9].Text = "0";
            TextBoxe[10].Text = "1";
            TextBoxe[11].Text = "0";
            TextBoxe[12].Text = "0";
            TextBoxe[13].Text = "0";
            TextBoxe[14].Text = "0";
            TextBoxe[15].Text = "1";
            textBoxes[0].Text = "1";
            textBoxes[1].Text = "0";
            textBoxes[2].Text = "0";
            textBoxes[3].Text = "0";
            textBoxes[4].Text = "0";
            textBoxes[5].Text = "1";
            textBoxes[6].Text = "0";
            textBoxes[7].Text = "0";
            textBoxes[8].Text = "0";
            textBoxes[9].Text = "0";
            textBoxes[10].Text = "1";
            textBoxes[11].Text = "0";
            textBoxes[12].Text = "0";
            textBoxes[13].Text = "0";
            textBoxes[14].Text = "0";
            textBoxes[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(TextBoxe[0].Text);
            a[1, 2] = Convert.ToInt16(TextBoxe[1].Text);
            a[1, 3] = Convert.ToInt16(TextBoxe[2].Text);
            a[1, 4] = Convert.ToInt16(TextBoxe[3].Text);
            a[2, 1] = Convert.ToInt16(TextBoxe[4].Text);
            a[2, 2] = Convert.ToInt16(TextBoxe[5].Text);
            a[2, 3] = Convert.ToInt16(TextBoxe[6].Text);
            a[2, 4] = Convert.ToInt16(TextBoxe[7].Text);
            a[3, 1] = Convert.ToInt16(TextBoxe[8].Text);
            a[3, 2] = Convert.ToInt16(TextBoxe[9].Text);
            a[3, 3] = Convert.ToInt16(TextBoxe[10].Text);
            a[3, 4] = Convert.ToInt16(TextBoxe[11].Text);
            a[4, 1] = Convert.ToInt16(TextBoxe[12].Text);
            a[4, 2] = Convert.ToInt16(TextBoxe[13].Text);
            a[4, 3] = Convert.ToInt16(TextBoxe[14].Text);
            a[4, 4] = Convert.ToInt16(TextBoxe[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]);
                }

        }
    }
}

沒有留言:

張貼留言