2014年11月7日 星期五

ooxx基礎

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 WindowsFormsApplication10
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.Button[] Buttons;


       System.Windows.Forms.Button Button1;
        public Form1()
        {
            InitializeComponent();
        }

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

     
               // 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 Button1_Click(object sender, EventArgs e)
        {
 Button btn = (Button)sender;
            MessageBox.Show(btn.Text);
   
         
        }
       
        private void APPLE()
        {
     
         // 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[9];

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



            for (int i = 0; i < 9; ++i)
            {
                Buttons[i] = new Button();

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


                if (i <= 2)

                    Buttons[i].Location = new System.Drawing.Point(100 + i * 100, 100);


                else if (i > 2 && i <= 5)
                    Buttons[i].Location = new System.Drawing.Point(100 + (i - 3) * 100, 200);
                else if (i > 5 && i <= 9)
                    Buttons[i].Location = new System.Drawing.Point(100 + (i - 6) * 100, 300);
                Buttons[i].Text = i.ToString();
                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(Button1_Click);
             
            }

     
     
     
     
        }


    }
}

沒有留言:

張貼留言