namespace WindowsApplication1
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
public void Form4_Load(object sender, EventArgs e)
{
//在窗体上呈现控件
string source = "Data source=zwl;User Id=sa;password=sa;database=noon";
SqlConnection conn = new SqlConnection(source);
conn.Open();
SqlCommand cmd1 = new SqlCommand("select count(*) as count from noonname", conn);
SqlDataReader o1;
o1 = cmd1.ExecuteReader();
o1.Read();
Label[] lbl = new Label[Convert.ToInt32(o1["count"])];
TextBox[] txt = new TextBox[Convert.ToInt32(o1["count"])];
conn.Close();
SqlCommand cmd = new SqlCommand("select * from noonname", conn);
conn.Open();
SqlDataReader o;
o = cmd.ExecuteReader();
int i = 0;
while (o.Read())
{
lbl[i] = new Label();
lbl[i].Location = new System.Drawing.Point(100 ,100+20 * i);
lbl[i].Size = new System.Drawing.Size(50,20);
lbl[i].Text = o["姓名"].ToString();
lbl[i].Visible = true;
this.Controls.Add(lbl[i]);
txt[i] = new TextBox();
txt[i].Location = new System.Drawing.Point(200, 100 + 20 * i);
txt[i].Name = "txt1";
txt[i].Size = new System.Drawing.Size(50, 20);
txt[i].Text ="0";
txt[i].Visible = true;
this.Controls.Add(txt[i]);
i++;
}
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
我想在button1_click里引用txt[0]的text内容,怎么作
參考答案:this.txt[0].text