using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { ((Button)sender).Text = "Clicked"; // 更改当前button的内容 Button newButton = new Button(); // 创建一个新的button newButton.Text = "newButton"; // 新Button显示的内容 newButton.Click += new EventHandler(NewButton_Click); // newButton.Click += NewButton_Click; Controls.Add(newButton); // 动态添加到窗口 } private void NewButton_Click(object sender, EventArgs e) { ((Button)sender).Text = "newClicked!"; } } }