Creating a textbox dynamically!!!
-
Hi, I'am trying 2 create a textbox dynamically in a windowsform application... I want a textbox 2 b created while clicking a button in the form...And it has 2 b loaded thru code rather than thru design ... I tried but was not able 2 create the control...Cud u pleez get me the code 4 this one..??? Thanx n Regards, MMX
-
Hi, I'am trying 2 create a textbox dynamically in a windowsform application... I want a textbox 2 b created while clicking a button in the form...And it has 2 b loaded thru code rather than thru design ... I tried but was not able 2 create the control...Cud u pleez get me the code 4 this one..??? Thanx n Regards, MMX
hi, this is the way how you do it ... private void button1_Click(object sender, System.EventArgs e) { TextBox tb = new TextBox(); tb.Width = 100; tb.Location = new Point(100,100); this.Controls.Add(tb); } Hope this solves your prob.. regards, Aryadip. Cheers !! and have a Funky day !!
-
hi, this is the way how you do it ... private void button1_Click(object sender, System.EventArgs e) { TextBox tb = new TextBox(); tb.Width = 100; tb.Location = new Point(100,100); this.Controls.Add(tb); } Hope this solves your prob.. regards, Aryadip. Cheers !! and have a Funky day !!
If you want to see all textbox which added to the form.then you can use the below mentioned code block private void button1_Click(object sender, System.EventArgs e) { Txtbox= new TextBox(); this.Txtbox.Location = new System.Drawing.Point(locx, locy); Txtbox.Width = 100; this.Controls.Add(Txtbox); locx=Txtbox.Location.X; locy=Txtbox.Location.Y+30; } //here i have only one button on my form. On button click i am dynamically creating //textbox control and adding to the control collection of form. //before getting into code you have to declare one private datamember of the type textbox and two integer variables that will help you to keep the location unique. so you can avoid overlapping. private System.Windows.Forms.TextBox Txtbox; private int locx=20,locy=30; hope this will avoid from overlapping:-O Sreejith S S Nair