我有一个textboxes
数组,它生成一个可变数量textboxes
的运行时,例如已经在表单中创建的textbox
的值。
int n;
TextBox[] tb;
public void AggiungiArmoniche()
{
n = int.Parse(textBox4.Text);
tb = new
TextBox[n];
for (int i = 1; i < tb.Length; i++)
{
tb[i] = new TextBox();
tb[i].Name = "textBox" + i;
tb[i].Location = new Point(100 *i, 163);
tb[i].Size = new Size(48, 20);
tb[i].KeyPress += System.Windows.Forms.KeyPressEventHandler(textBoxP_KeyPress);
groupBox1.Controls.Add(tb[i]);
}
}
private void textBoxP_KeyPress(object sender, KeyPressEventArgs e)
{
// statements of the event
}
当我移动到我将事件与事件处理程序关联的行时,它会给出错误它不是竞赛中的有效构造“(特别是在单词keypresseventhandler
中)
关联中是否存在语法错误?
答案 0 :(得分:1)
删除KeyPressEventHandler并添加事件处理程序,如此
tb[i].KeyPress += textBoxP_KeyPress;
答案 1 :(得分:0)
新
tb[i].KeyPress += new System.Windows.Forms.KeyPressEventHandler(textBoxP_KeyPress);