Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create textbox or combobox on user request. i mean i have made a button now if any one click on it a textbox should be appear.
Posted

C#
private void button1_Click_1(object sender, EventArgs e)
        {
            Button btnAdd = new Button();

            btnAdd.BackColor = Color.Gray;
            btnAdd.Text = "Add";
            btnAdd.Location = new System.Drawing.Point(90, 25+i);
            btnAdd.Size = new System.Drawing.Size(50, 25);
            this.Controls.Add(btnAdd);
            i = i + 10;
        }


also if you create the control(drag and drop) and make it visible = false and on click...change it into true (visible = true).
 
Share this answer
 
Comments
Muhamad Faizan Khan 17-Oct-13 9:45am    
if user want 50 text boxes then i cant invisible and place 50 textboexes
Member 10266297 17-Oct-13 9:50am    
so create them dynamically as the example above
Muhamad Faizan Khan 17-Oct-13 9:55am    
what does i doing??
Member 10266297 17-Oct-13 10:07am    
Label label = new Label();
label.Text = "text";
label.BorderStyle = BorderStyle.FixedSingle;
label.SetBounds(myPanel.Bounds.X + 1, myPanel.Bounds.Y + 5, 100, 20);
myPanel.Controls.Add(label);

this is the way how to create control at run time i use it and it is working well try it on button click of your application
Add Textbox/Combobox on form set the visibility false on Page Load.In Button Click event set the visibility to true.
 
Share this answer
 
v2
Comments
Muhamad Faizan Khan 17-Oct-13 9:46am    
if user want 50 text boxes then i cant invisible and place 50 textboexes
shock.er 17-Oct-13 11:40am    
Hi, just wondering what you mean when you say you can't make it invisible. What do you want to be invisible when you click the button? Do you want the button to become invisible after you've created the textboxes?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900