Creating Dynamic TextBox and Get Its Value

private void button1_Click(object sender, EventArgs e)
{
int cnt = 0;
int x = 88;
int y = 50;
for (int i = 0; i <Convert.ToInt32(xxx.Text); i++)
{
TextBox textbox = new TextBox();
Label label = new Label();
label.Location=new Point(x,Convert.ToInt32(y-25));
label.Name = "label" + cnt.ToString();
label.Size = new System.Drawing.Size(173, 20);
label.Text = "label" + cnt.ToString();
label.Visible = true;
textbox.Location = new System.Drawing.Point(x, y);
textbox.Name = "textbox" + cnt.ToString();
textbox.Size = new System.Drawing.Size(173, 20);
textbox.TabIndex = cnt;

textbox.Visible = true;
cnt++;
y += 50;
panel1.Controls.Add(textbox);
panel1.Controls.Add(label);

}
}

private void button2_Click(object sender, EventArgs e)
{
string OptionID = "textbox" + 1;
TextBox tb = (TextBox)panel1.Controls[OptionID];
MessageBox.Show(tb.Text);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: