How To Add Controls To Window Form At Run Time

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. namespace How_to_add_controls_dynamically {  
  10.     public partial class Form1: Form {  
  11.         int controlleft = 1;  
  12.         public Form1() {  
  13.             InitializeComponent();  
  14.         }  
  15.         private void button1_Click(object sender, EventArgs e) {  
  16.             TextBox txt = new TextBox();  
  17.             this.Controls.Add(txt);  
  18.             txt.Top = controlleft * 25;  
  19.             txt.Left = 100;  
  20.             controlleft = controlleft + 1;  
  21.         }  
  22.     }  
  23. }