0

我有一个数组,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

关联中是否存在语法错误?

4

2 回答 2

1

删除 KeyPressEventHandler 并像这样添加事件处理程序

tb[i].KeyPress += textBoxP_KeyPress;
于 2013-01-16T23:13:33.107 回答
0

新的

tb[i].KeyPress += new System.Windows.Forms.KeyPressEventHandler(textBoxP_KeyPress);
于 2013-01-16T23:05:02.620 回答