1
Reply

How to remove dynamic control from Form

Arun Kurmi

Arun Kurmi

Mar 19 2013 11:12 AM
939
I have 2 problems related to dynamic control.

1)
I hava a array txt to cteate no. of dynamic textbox at run time, i does this  successfully.I want remove previously created textbox and add new textboxes to form on button click.

        private void button1_Click(object sender, EventArgs e)
        {
            //txt.Controls.Remove();
            //txt[n].Controls.Clear();
                n=Convert.ToInt16(textBox1.Text);
                txt = new TextBox[n];
                for (int i = 0; i < n; i++)
                {
                   
                    txt[i] = new TextBox();
                    this.Controls.Add(txt[i]);
                    txt[i].Location = new Point(textBox1.Location.X, textBox1.Location.Y + (i + 1) * 40);
                    txt[i].BackColor = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
                    txt[i].Text = "This is Dynamic TextBox" + (i + 1);
                    txt[i].Size = new Size(150, 10);


                }
        }

-----------------------------------------------------------------------
2)
how to use textbox.text property with dynamic textbox to use text of textbox.
for ex. i want display a messegebox with text of dynamic textbox.
 

Answers (1)