C# Create Dynamic Buttons and onClick Dynamic EventHandlers

后端 未结 2 2070
不知归路
不知归路 2020-12-04 01:14

My program creates buttons dynamically.

private void CreateButton(string buttonName)
{

   Color[] c = { Color.Red, Color.Teal, Color.Blue, Color.WhiteSmoke          


        
2条回答
  •  不知归路
    2020-12-04 01:34

    You have a reference to the button that was clicked right there as the sender argument. So...

    private void transbutton_Click(object sender, EventArgs e)
        {
           tbList.Text += "\r\n" + ((Button)sender).Text;
        }
    

提交回复
热议问题