using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
namespace CaiCaiKan {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
System.Threading.Thread Gthread;//定义线程
Random Grandom = new Random();//定义随机数对象
int Gnum;//定义变量用于存放存机数
private void btnStart_Click(object sender, EventArgs e) {
RemoveControl();//清空所有无用对象
btnStart.Enabled = false;//设置开始按钮不可用
//生成100个按钮,10横10竖
int px = 10;//第一个按钮的位置
int py = 60;
for (int i = 0; i < 100; i++) {
Button btn = new Button();//给按钮赋值,定义宽和高
btn.Name = (i+1).ToString();
btn.Text = (i+1).ToString();
btn.Width = 35;
btn.Height = 35;
btn.Location = new Point(px, py);
btn.Click += new EventHandler(btn_Click);//定义按钮事件
px += 36;
if ((i + 1) % 10 == 0) {
px = 10;
py += 36;
}
Controls.Add(btn);//将button按钮放入窗体控件集合中
}