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 WindowsFormsApplication13
{
    public partial class Form1 : Form
    {

        Button[,] Buttons =new Button[5,5];//5*5格子
     
        Random irand = new Random(Guid.NewGuid().GetHashCode());
     





        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           // APPLE();

            int a = 70;
            int b = 60;

            int r;
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    Random irand = new Random(Guid.NewGuid().GetHashCode());
                    Buttons[i, j] = new Button();
                    Buttons[i, j].Location = new Point(i * 60, j * 70 + 10);//算格子堅格寬度
                    this.Controls.Add(Buttons[i, j]);
                    Buttons[i, j].Size = new System.Drawing.Size(a, b);
                    r = irand.Next(0, 15);
                    Buttons[i, j].Text = r.ToString();//轉,顯示



//以下是其他的東西有興趣可以用來玩玩

                    // Button1 = new System.Windows.Forms.Button();
                    // Button1.Location = new Point(100, 100);
                    //Button1.Size = new System.Drawing.Size(200, 200);
                    //Button1.Click += new EventHandler(Button1_Click);
                    //Button1.BackColor = Color.Green;
                    // this.Controls.Add(Button1);

                }
            }
        }
//        private void APPLE()
  //      {
    //        int r;
     
         // Button1 = new System.Windows.Forms.Button();
           // Button1.Location = new Point(100, 100);
          //  Button1.Size = new System.Drawing.Size(200, 200);
           // this.Controls.Add(Button1);
      //    int width, height;
         
        //    width = this.Size.Width;
          //  height = this.Size.Height;

            //Buttons = new System.Windows.Forms.Button[16];

         //   width= 100;
          //  height= 100;



        //    for (int i = 0; i < 16; ++i)
          //  {
             

            //    Random irand = new Random(Guid.NewGuid().GetHashCode());
             
              //  Buttons[i] = new Button();

                //this.Controls.Add(Buttons[i]);


             

                  //  Buttons[i].Location = new System.Drawing.Point(300 + i * 100, 100);
                //else if (i > 3 && i <= 7)
                 //   Buttons[i].Location = new System.Drawing.Point(200 + (i - 3) * 100, 200);
               // else if (i > 7 && i <= 11)
                //    Buttons[i].Location = new System.Drawing.Point(100 + (i - 6) * 100, 300);
               // else if (i > 11 && i <= 16)
                 //   Buttons[i].Location = new System.Drawing.Point(0 + (i - 9) * 100, 400);

                //Buttons[i].Text = irand.ToString();
               //r=irand.Next(0,15);
               // Buttons[i].Size = new Size(width, height);
               // Buttons[i].Size = new System.Drawing.Size(100, 100);
              //  Buttons[i].BackColor = Color.Green;
               // Buttons[i].Click += new EventHandler(Buttons_Click);

            }
        }


//private void Buttons_Click(object sender, EventArgs e)
  //      {

    //                 Button btn = (Button)sender;
      //      MessageBox.Show(btn.Text);
        //    for (int i = 0; i < 16; ++i)
          //  {
            //    Buttons[i] = new Button();
                       
              //  this.Controls.Add(Buttons[i]);              
             
            //}
        //}
    //}
//}

沒有留言:

張貼留言