2014年12月25日 星期四

C#6

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 WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[5, 5];//宣告一矩陣(10x10)
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            Random crandom = new Random();
           
              
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Size = new Size(50, 50);
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i, j].Text = crandom.Next(1,15).ToString();
                    this.Controls.Add(buttons[i, j]);//將物件顯示
                   
                }
        
            }
    }
}
}

沒有留言:

張貼留言