Skip to main content

Generate Textbox Dynamically at Runtime in windows Form Application


In this article we generate textbox at runtime.we give the quantity of textbox which we want to generate in textbox.it will generate textbox .

Step 1:
Open visual studio--->File--->New--->Project---->WindowsFormApplication

                           
Step 2:
Drag panel1 , panel2,textBox1 and button from a toolbox window.
                     
                         
Step 3:
Now Doubble click on click me button and write the following code:
       try
            {

                int txtno = int.Parse(txt1.Text);
                int pointX = 30;
                int pointY = 40;

                panel2.Controls.Clear();

                for (int i = 0; i < txtno; i++)
                {

                    TextBox a = new TextBox();
                    a.Text = (i + 1).ToString();
                    a.Location = new Point(pointX, pointY);
                    panel2.Controls.Add(a);
                    panel2.Show();
                    pointY += 20;
                }
            }
            catch (Exception)
            {

                MessageBox.Show(e.ToString());
            }

Step4:
Press F5 and run . Enter the no in textbox, it will generate textbox.
eg: here we enter 4 in textbox , so its generate 4 textbox.





Comments

Popular posts from this blog

How to Pass Data from one Form to other Form in windows Form Application C#

Introduction: Hi Guys! In this tutorial we learn how to pass data from one form to other form in windows form application using c#. Let’s Follow the Step and create windows form application. Step1: Visual studio- à File- à New- à Project à windows Form Application- à Ok Step2: Click on ToolBox- à Drag and drop Label and TextBox. I creat a Form with 3 Labels and TextBox as shown in fig. Step 3: I have Name,Fname,Address Label on Form .so I take a three global variable .Write this code on the Form1.cs         public static string SetValueForText1 = "" ;         public static string SetValueForText2 = "" ;         public static string SetValueForText3 = "" ; Step4: Project- à Add Windows Form- à Click on Add Step 5: After Creating Form Double Click on Submit button on windows Form1 and Write the Cod...