主题:为什么和书上的一模一样会出错,一个窗口问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
((button)sender).Text = "clicked!";
Button newbutton =new Button();
newbutton.Text = "new button!";
newbutton.Click+=new EventHandler(newbutton_Click);
Control.Add(newbutton);
}
private void newbutton_Click(object sender, System.EventArgs e)
{
((button)sender).Text = "clicked!!!";
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
((button)sender).Text = "clicked!";
Button newbutton =new Button();
newbutton.Text = "new button!";
newbutton.Click+=new EventHandler(newbutton_Click);
Control.Add(newbutton);
}
private void newbutton_Click(object sender, System.EventArgs e)
{
((button)sender).Text = "clicked!!!";
}
}
}