在Form中画一个textBox1,textBox2和一个button1,button2 namespace WindowsFormsApplication5 {
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent(); } private void button1_Click(object sender, EventArgs e)
{
TextBox[] TB = new TextBox[2];
TB[0] = textBox1;
TB[1] = textBox2;
} private void button2_Click(object sender, EventArgs e)
{
TB[0].Text = 1;
}
}
} 程序如上,当我运行程序时报告错误,TB变量在button2_Click事件中为定义,请问如何在C#中定义全局使用的控件数组
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent(); } private void button1_Click(object sender, EventArgs e)
{
TextBox[] TB = new TextBox[2];
TB[0] = textBox1;
TB[1] = textBox2;
} private void button2_Click(object sender, EventArgs e)
{
TB[0].Text = 1;
}
}
} 程序如上,当我运行程序时报告错误,TB变量在button2_Click事件中为定义,请问如何在C#中定义全局使用的控件数组
TextBox[] TB= new TextBox[2];
private void button1_Click(object sender, EventArgs e)
{
TB[0] = textBox1;
TB[1] = textBox2;
} private void button2_Click(object sender, EventArgs e)
{
TB[0].Text = 1;
}