如何在C#中创建和调用动态实例化的方法?

时间:2017-11-09 12:59:13

标签: c# user-interface methods

[C#]您好,我的程序有点问题。每次按下按钮,我都会创建文本框和按钮。我想为每个按钮创建一个循环方法,稍后,可以调用该方法,以便在单击按钮时,删除文本框和按钮本身。我如何创建这些方法?如何将这些中的每一个分别调用到循环中的按钮名称(例如button01,button02 ... button35)?我做了一个来测试它,但它不起作用。有人能指出我正确的方向吗?怎么办?

TextBox fieldA = new TextBox();
            fieldA.Name = "fieldA" + i;
            fieldA.Text = "fieldA"+i;
            fieldA.Location = new Point(x[0], y[i]);
           Controls.Add(fieldA);
            textBoxListA[i] = fieldA;


            Button buttonA = new Button();
            buttonA.Name = "button" + i; // its name is  button0 
            buttonA.Text = "button" + i;
            buttonA.Location= new Point(x[3], y[i]);
            Controls.Add(buttonA); 

private void button0_Click(object sender, EventArgs e)] // im trying to call it but it wont work 
    {
        //code to delete textboxes and this button
    }

0 个答案:

没有答案