17,740
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace HoverTreeForms
{
public partial class HewenqiForm : Form
{
List<Button> _btnList = new List<Button>();
public HewenqiForm()
{
InitializeComponent();
NewWall();
}
void NewWall()
{
for (int i = 0; i < 315; i++)
{
Button h_btn = new Button();
h_btn.Size = new Size(40, 40);
h_btn.BackColor = Color.Green;
h_btn.Tag = i.ToString();
h_btn.Click += Btn_Click;
_btnList.Add(h_btn);
flowLayoutPanel1.Controls.Add(h_btn);
}
AddWall();
foreach (Control c in flowLayoutPanel1.Controls)
{
c.Margin = new Padding(-1);
}
}
private void Btn_Click(object sender, EventArgs e)
{
MessageBox.Show(((Button)sender).Tag.ToString());//点击会显示第几个按钮 by HoverTree
}
void AddWall()
{
int h_num = 0;
Random h_random = new Random();//参考 http://hovertree.com/h/bjag/ttoqk342.htm
for (int i = 0; i < 10; i++)
{
h_num = h_random.Next(2, 315);
_btnList[h_num].BackColor = Color.Yellow;
}
}
}
}
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
var a = new Random();
Console.WriteLine(a.Next(2,315));
}
Console.ReadLine();
}
static void Main(string[] args)
{
var a = new Random();
for (int i = 0; i < 10; i++)
{
Console.WriteLine(a.Next(2,315));
}
Console.ReadLine();
}
你跑下这两段代码你就懂了,同意1楼