我想为txt创建一个方法,但我不知道怎么做。我记得那是一件带有"=>"操作符,但我记不起正确的语法。有人能帮帮我吗?这是代码:
private void button1_Click(object sender, EventArgs e)
{
ex_y += 25;
n = int.Parse(textBox1.Text);
for (int i = 0; i < n; i++)
{
Button b = new Button();
this.Controls.Add(b);
b.Size = new Size(50, 50);
b.Location = new Point(ex_x + b.Width + 25, ex_y);
ex_x = b.Location.X;
b.Text = rand.Next(0, 100).ToString();
a[i] = int.Parse(b.Text);
rand.Next(0, 100);
TextBox txt = new TextBox();
this.Controls.Add(txt);
txt.Size = new Size(b.Size.Width, 50);
txt.Location = new Point(b.Location.X, b.Location.Y + 60);
txt.BackColor = Color.White;
}
}
从技术上讲,您需要订阅事件,这是通过+=
操作符完成的。这是官方文件。
例如:
private void button1_Click(object sender, EventArgs e)
{
Button b = new Button();
b.Click += new System.EventHandler(b_Click);
this.Controls.Add(b);
b.Size = new Size(50, 50);
}
private void b_Click(object sender, EventArgs e)
{
MessageBox.Show("I was clicked!");
}