close

1107  

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
{
//public System.Windows.Forms.Button Button1;

System.Windows.Forms.Button[] Buttons;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
button();
for (int i = 0; i < Buttons.Length; i++)
{
int index = i;
Buttons[i].Click += (sender1, ex) => this.Display(index + 1);
this.Controls.Add(Buttons[i]);
}

/*Button1 = new System.Windows.Forms.Button();
Button1.Location = new Point(100, 100);
Button1.Size = new Size(100, 100);
Button1.Text = "Hello!";
Button1.BackColor = Color.SeaGreen;
Button1.Click += new EventHandler(Button1_Click);
this.Controls.Add(Button1);*/
}
public void Display(int i)
{
MessageBox.Show("Button number is " + i);
}

/*
protected void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello!");
}
*/
private void button()
{
int width, height;
/*Button1 = new System.Windows.Forms.Button();
Button1.Location = new Point(100, 100);
Button1.Size = new Size(100, 100);
Button1.Text = "Hello!";
this.Controls.Add(Button1);*/
width = 60;
height = 60;

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

Buttons[i] = new Button();
Buttons[i].Size = new Size(width, height);
Buttons[i].Text = i.ToString();
Buttons[i].BackColor = Color.Peru;

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

if (i <= 2)
Buttons[i].Location = new System.Drawing.Point(150 + i * 60, 110);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(150 + (i - 3) * 60, 170);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(150 + (i - 6) * 60, 230);
}
}
}
}

arrow
arrow
    全站熱搜

    芫兒 發表在 痞客邦 留言(0) 人氣()