How to dynamically add controls to your user interface in c#.net

CONTROLS C# DYNAMICALLY

C# Tutorials

  

CONTROLS C SHARP DYNAMICALLY

Learn Tutorials
How to dynamically add controls to your user interface in c#.net

Example code for Controls c sharp dynamically:
public void AddControls(Form theForm)
      {
         Hashtable textBoxHT=new Hashtable();
         int yPos=10;
         theForm.SuspendLayout();

         foreach(string stringInArray in controlItemsList)
         {
            //Console.WriteLine("added "+stringInArray);
      
            Label tempLabel=new Label();
            tempLabel.Width=138;
            tempLabel.TextAlign=ContentAlignment.MiddleRight;
            tempLabel.Text=stringInArray+":";
            tempLabel.Location=new System.Drawing.Point(10, yPos);      

            TextBox tempShortText=new TextBox();
            tempShortText.Location=new System.Drawing.Point(150, yPos);
            tempShortText.Width=100;         
            //tempShortText.Text=stringInArray;//get this from the XML

            TextBox tempLongText=new TextBox();
            tempLongText.Location=new System.Drawing.Point(270, yPos);
            tempLongText.Width=250;         
            //tempLongText.Text=stringInArray;//get this from the XML


            theForm.Controls.Add(tempShortText);
            theForm.Controls.Add(tempLongText);
            theForm.Controls.Add(tempLabel);
            yPos+=22;
         }
         theForm.ResumeLayout();

      }
This is example code for how to dynamically add controls to your user interface in c#.net