button2.Click += new System.EventHandler(this.button2_Click);
private void button1_Click(object sender, System.EventArgs e)
{
 ...}

解决方案 »

  1.   


    上面错误
    button2.Click += new System.EventHandler(this.button2_Click);
    private void button2_Click(object sender, System.EventArgs e)
    {
     ...}
      

  2.   

    to :HNU 你好,多谢你回答我的问题,我意思是按button1后新建一个button2.那么怎样给它加事件响应如下:
    private void button1_Click(object sender, System.EventArgs e)
    {
    System.Windows.Forms.Button button2 = new System.Windows.Forms.Button();
    button2.Location = new System.Drawing.Point(120, 100);
    button2.Name = "button2";
    button2.Size = new System.Drawing.Size(80, 24);
    button2.TabIndex = 0;
    button2.Text = "button2";
    this.Controls.Add(button2);(至此已经新建一个按钮了。但怎样加入事件响应)
    .
    .}
    响应函数应该怎样加入。你说的方法我之前已经试过,
    button2.Click += new System.EventHandler(this.button2_Click);但是是没有this.button2_Click这个方法的。因为根本还没有定义。应定义在那里。
      

  3.   

    就定义在你的Form类下面
    private void button2_Click(object sender, System.EventArgs e)
    {
     ...}
      

  4.   

    你只要打入:button2.Click += 注意到这儿时,它会提示你按Tab键的,那你就按吧~~好了,完工
      

  5.   


    private void btnTest1_Click(object sender, System.EventArgs e)
    {
     Button btnTest2 = new Button();
     btnTest2.Name = "btnTest2";
     btnTest2.Text = "按钮2";
     btnTest2.Size = btnTest1.Size;
     btnTest2.Location = new Point(btnTest1.Location.X + btnTest1.Size.Width + 5, btnTest1.Location.Y);
     btnTest2.Click+=new EventHandler(btnTest2_Click);
     this.Controls.Add(btnTest2);
    }
    private void btnTest2_Click(object sender, EventArgs e)
    {
     MessageBox.Show("Hello,World");
    }
      

  6.   

    响应函数应该怎样加入。你说的方法我之前已经试过,
    button2.Click += new System.EventHandler(this.button2_Click);但是是没有this.button2_Click这个方法的。因为根本还没有定义。应定义在那里。
    ========》
    再类里面定义就行了,其实手动添加事件设计器会提示你按tab键生成方法的。