How to add buttons dynamically to my form?

前端 未结 8 1892
盖世英雄少女心
盖世英雄少女心 2020-12-01 12:34

I want to create 10 buttons on my form when I click on button1. No error with this code below but it doesnt work either.

private void button1_Click(object se         


        
8条回答
  •  时光说笑
    2020-12-01 13:09

    You can't add a Button to an empty list without creating a new instance of that Button. You are missing the

    Button newButton = new Button();  
    

    in your code plus get rid of the .Capacity

提交回复
热议问题