我的程序动态地创建按钮。C#创建动态按钮和onClick动态事件处理程序
private void CreateButton(string buttonName)
{
Color[] c = { Color.Red, Color.Teal, Color.Blue, Color.WhiteSmoke };
transbutton = new Button();
transbutton.BackColor = c[2];
transbutton.Text = buttonName;
transbutton.Name = buttonName + "Button";
transbutton.Width = 150;
transbutton.Height = 150;
transbutton.Font = new Font("Segoe UI", 13);
transbutton.ForeColor = Color.White;
transbutton.Click += new EventHandler(transbutton_Click);
}
private void transbutton_Click(object sender, EventArgs e)
{
tbList.Text = transbutton.Text;
}
我所试图做的是,当用户点击该按钮(一个或多个),它增加了一键进入多行TextBox的名称,如在上面的图片。我创建了一个EventHandler,但不知道如何使它与动态按钮一起工作。
你将你的按钮在屏幕/形式的价值? (我没有在你的代码中看到一个电话) – gunr2171 2013-05-02 20:41:09