2014年12月5日 星期五

C#7

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 WindowsFormsApplication13
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[5, 5];

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int x;
            int width, height;
            int[] myarray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
            // Instantiating all the buttons in the array



            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    //x = (i + 1) * (j + 1);
                    x = myarray[(i - 1) * 4 + j - 1];

                    width = 50;
                    height = 50;
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i, j].Text = x.ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    int w;
                    Random r = new Random();
                    w = r.Next(0, j);
                    tmp = list[0];
                    list[0] = list[w];
                    list[w] = tmp;

                }
            }


        }
    }


}

2014年11月28日 星期五

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];
        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]);
                   
                }
       
            }
    }
}
}