2012-10-23 87 views
-2

我想使功能工作:VS10 C#功能運行後點擊

INT A = Convert.ToInt32(TB [0]。文本);

後我點擊:

Button1的

後按鈕點擊一下如何更新文本框的值?

//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){} 
+0

之所以如此,是錯誤的,這種局部的事情。 – legend1337

回答

0
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); 
    } 
} 
+0

這是一個靜態的例子。如果我想添加一些動態事件處理程序,我會寫這個: button1.click + = eventHandlerType(Method_name); – legend1337