2010年10月22日 星期五

數字遊戲(未完成版)

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        System.Windows.Forms.Button[] Buttons;
        System.Windows.Forms.TextBox[] TextBoxs;
        public Form1()
        {
            InitializeComponent();
        }
      
        private void Form1_Load(object sender, EventArgs e)
        {
            Buttons = new System.Windows.Forms.Button[9];
            TextBoxs = new System.Windows.Forms.TextBox[9];
          
            for (int i = 0; i <9; ++i)
            {
                Buttons[i] = new Button();
                Buttons[i].Click += new System.EventHandler(Buttons_Click);
                this.Controls.Add(Buttons[i]);
                if (i <= 2)
                    Buttons[i].Location = new System.Drawing.Point(10 + i * 120, 110);
                else if (i > 2 && i <= 5)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 3) * 120, 140);
                else if (i > 5 && i <= 9)
                    Buttons[i].Location = new System.Drawing.Point(10 + (i - 6) * 120, 170);
            }

            for (int i = 0; i < 9; ++i)
            {
                TextBoxs[i] = new TextBox();
                this.Controls.Add(TextBoxs[i]);
                if (i <= 2)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + i * 110, 10);
                else if (i > 2 && i <= 5)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 3) * 110, 40);
                else if (i > 5 && i <= 9)
                    TextBoxs[i].Location = new System.Drawing.Point(10 + (i - 6) * 110, 70);
            }


            TextBoxs[0].Text = "7";
            TextBoxs[1].Text = "2";
            TextBoxs[2].Text = "4";
            TextBoxs[3].Text = "5";
            TextBoxs[4].Text = "0";
            TextBoxs[5].Text = "6";
            TextBoxs[6].Text = "8";
            TextBoxs[7].Text = "3";
            TextBoxs[8].Text = "1";
           

          
        }
        public void Buttons_Click(object sender, EventArgs e)
        {
            // System.Windows.Forms.MessageBox.Show("You have clicked button " +
            //   ((System.Windows.Forms.Button)sender).Tag.ToString());
            MessageBox.Show("button_click"+sender.ToString());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 9; i++)
            {
                Buttons[i].Text = Convert.ToString(TextBoxs[i].Text);
            }
        }
    }
}

沒有留言:

張貼留言