2015年10月30日 星期五

1~16順訊排列

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
       
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 1; i < 5; ++i)
            {

                for (int j = 1; j < 5; ++j)
                {
                    Buttons[i, j] = new Button();                  //利用二維陣列產生4x4按鈕
                    Buttons[i, j].Location = new Point(i * 100, j * 100);     //改變其按鈕位置
                    Buttons[i, j].Size = new Size(100, 100);            //改變按鈕大小
                    this.Controls.Add(Buttons[i, j]);     //要產生按鈕一定要有這行

                }
            }
        }
        private void button1_Click(object sender, EventArgs e)   //按下button1就可以產生亂數
        {
            int pro = 0;
            for (int i = 1; i < 5; i++)
            {
         
                for (int j = 1; j <2; j++)
                {
                    pro = i*j;
                    Buttons[i, j].Text = pro.ToString();
                 
                }
            }
            for (int i = 1; i < 5; i++)
            {

                for (int j = 2; j < 3; j++)
                {
                    pro = 4+i;
                    Buttons[i, j].Text = pro.ToString();

                }
            }
            for (int i = 1; i < 5; i++)
            {

                for (int j = 3; j < 4; j++)
                {
                    pro = 8 + i;
                    Buttons[i, j].Text = pro.ToString();

                }
            }
            for (int i = 1; i < 5; i++)
            {

                for (int j = 4; j < 5; j++)
                {
                    pro = 12 + i;
                    Buttons[i, j].Text = pro.ToString();

                }
            }
         

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click_1(object sender, EventArgs e)
        {

        }
    }
}

沒有留言:

張貼留言