Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vs10 c#功能在单击后运行_C#_Winforms - Fatal编程技术网

vs10 c#功能在单击后运行

vs10 c#功能在单击后运行,c#,winforms,C#,Winforms,我想让功能正常工作: int a=Convert.ToInt32(tb[0].Text) 点击后: 按钮1 单击按钮1后如何更新文本框值 //My Code private void somefunction(){ TextBox[] tb = new TextBox[2]; for (int i = 0; i <= 1; i++) { tb[i] = new TextBox(); tb[i].Name = "textBox" + i;

我想让功能正常工作:

int a=Convert.ToInt32(tb[0].Text)

点击后:

按钮1

单击按钮1后如何更新文本框值

//My Code  
    private void somefunction(){
    TextBox[] tb = new TextBox[2];
    for (int i = 0; i <= 1; i++)
    {
    tb[i] = new TextBox();
    tb[i].Name = "textBox" + i;
    tb[i].Location = new Point(50 * i, 10);
    tb[i].Size = new System.Drawing.Size(20, 15);
    this.Controls.Add(tb[i]);     
    }

    //this code is static, how to make it update on click?
    int a, b;           
    a = Convert.ToInt32(tb[0].Text);
    b = Convert.ToInt32(tb[1].Text);
    }
// click event
    private void button1_Click(object sender, EventArgs e){}
//我的代码
私有函数(){
TextBox[]tb=新的TextBox[2];

对于(inti=0;i,这是非常错误的,这个本地化的东西。这是一个静态的例子。如果我想添加一些动态事件处理程序,我会这样写:button1.click+=eventHandlerType(方法名称);
public partial class Form1 : Form
{

    TextBox[] tb;

    public Form1()
    {
        InitializeComponent();
        tb = new TextBox[2];
        //...
    }

    private void button1_Click(object sender, EventArgs e)
    {
        int a = Convert.ToInt32(tb[0].Text);
    }
}