How to add controls dynamically in windows form c#

Visual studio provide the best features to design the form. By the designer window, you can add the controls from the toolBox. After added the items, you can set the properties by the property window. Same this things, you can do this by the code window. Follow some steps to add controls dynamically.

  Step-1 : Open Code window that is form1.cs file, create a object for controls like

TextBox t1 = new TextBox();

Step-2 : Associate properties of the TextBox class with the current object like

 t1.Name = "Text1";
    t1.Width = 300;
            t1.Text = " Dynamically added Control";
            t1.Location = new Point(10, 10);

Here Point is a class, in which you have to define the coordinates of x-axis and y-axis, where you want to add the TextBox.

Step-3 : Add this instance in the form by following line of code.


 Now code Generate the following output:
How to add controls dynamically in windows form c#


  1. Blogs are so informative where we get lots of information on any topic. Nice job keep it up!!
    A1 English Test Pakistan


Post a Comment

Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites