发布网友 发布时间:2023-11-10 06:55
共1个回答
热心网友 时间:2024-12-05 19:29
namespace 抽奖
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Random ran = new Random();
private void button1_Click(object sender, EventArgs e)
{
panel1.Controls.Clear();
try
{
for (int i = 0; i < Convert.ToInt32(textBox1.Text); i++)//····textbox1是显示button数
{
Button btn = new Button();
btn.Name = i.ToString();
btn.Text = ran.Next(Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox3.Text)).ToString();//·····textbox2和textbox3是抽奖数范围
btn.Location = new Point(8 + i * 80, 8);
panel1.Controls.Add(btn);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}
}
没有考虑按钮到容器的边界问题,我也是刚刚学习C#没几天,希望能帮到你