2014年12月7日 星期日

11/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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
System.Windows.Forms.Button Button1;//產生一個按鈕
System.Windows.Forms.Button[] Buttons;//產生數個按鈕
public Form1()
{
InitializeComponent();
}
int aa;
private void Form1_Load(object sender, EventArgs e)
{
// Button1 = new System.Windows.Forms.Button();
//Button1.Click += new System.EventHandler(Button1_Click);
// this.Controls.Add(Button1);
/*測試單一按鈕*/
mybuttons( aa );
}

private void Button_Click(Object sender, EventArgs e)
{
Button number = (Button)sender;
MessageBox.Show(number.Text);
}

private void mybuttons(int i)
{
Buttons = new System.Windows.Forms.Button[9];

for ( i = 0; i < 9; i++)
{

Buttons[i] = new Button();
Buttons[i].Text = i.ToString();
Buttons[i].BackColor = Color.White;
this.Controls.Add(Buttons[i]);

Buttons[i].Click += new System.EventHandler(Button_Click);

if (i <= 2)
{
Buttons[i].Location = new System.Drawing.Point(100 + i * 200, 50);
Buttons[i].Size = new Size(100, 100);

}

else if (i > 2 && i <= 5)
{
Buttons[i].Location = new System.Drawing.Point(100 + (i - 3) * 200, 200);
Buttons[i].Size = new Size(100, 100);

}
else if (i > 5 && i <= 9)
{
Buttons[i].Location = new System.Drawing.Point(100 + (i - 6) * 200, 350);
Buttons[i].Size = new Size(100, 100);

}

}
}
}
}


0 個意見:

張貼留言

訂閱 張貼留言 [Atom]

<< 首頁