ایجاد کنترل: [CSHARP] private void Form1_Load(object sender, EventArgs e) { List<Button> buttons = new List<Button>(); for (int i = 0; i < 10; i++) { Button btn = new Button(); btn.Size = new Size(120, 22); btn.Text = string.Format("Button{0}", i); btn.Location = new Point(10, i * 25 + 10); buttons.Add(btn);
} this.Controls.AddRange(buttons.ToArray());
}
[/CSHARP] اختصاص رویداد: [CSHARP] private void Form1_Load(object sender, EventArgs e) { List<Button> buttons = new List<Button>(); for (int i = 0; i < 10; i++) { Button btn = new Button(); btn.Size = new Size(120, 22); btn.Text = string.Format("Button{0}", i); btn.Location = new Point(10, i * 25 + 10); btn.Click += new EventHandler(btn_Click); buttons.Add(btn);
} this.Controls.AddRange(buttons.ToArray());
}

void btn_Click(object sender, EventArgs e) { for (int i = 0 ; i < 10 ; i++) { Button btn = sender as Button; btn.Location = new Point(btn.Left + i, btn.Top); Application.DoEvents(); } }
[/CSHARP]