Apo*_*llo 1 c# visual-studio-2010 winforms
我的程序动态创建按钮.
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;
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是当用户点击按钮时,它将按钮的名称添加到多行TextBox中,如上图所示.我创建了一个EventHandler,但无法弄清楚如何使它与动态按钮一起使用.
您可以参考在那里单击的按钮作为sender
参数.所以...
private void transbutton_Click(object sender, EventArgs e)
{
tbList.Text += "\r\n" + ((Button)sender).Text;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5817 次 |
最近记录: |