How to add buttons dynamically to my form?

前端 未结 8 1891
盖世英雄少女心
盖世英雄少女心 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:01

    Two problems- List is empty. You need to add some buttons to the list first. Second problem: You can't add buttons to "this". "This" is not referencing what you think, I think. Change this to reference a Panel for instance.

    //Assume you have on your .aspx page:
    
    
    
    private void button1_Click(object sender, EventArgs e)
        {
            List

提交回复
热议问题