سلام
TextBox text;
private List<Label> AddControl()
{
List<Label> lblList = new List<Label>();
for (int i = 0; i < 10; i++)
{
text = new TextBox();
this.text.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.text.Name = "textBox" + i.ToString();
this.text.Text = "textBox" + i.ToString();
if (i == 3)
this.text.KeyPress += new KeyPressEventHandler(textBox);
this.Controls.Add(text);
}
return lblList;
}
private void textBox(object sender, KeyPressEventArgs e)
{
MessageBox.Show(e.KeyChar.ToString());
}