1)在窗体Form1上布置一个Label
2)Form1的后台代码
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
Button btn;
public Form1()
{
InitializeComponent();
// 动态添加按钮
btn = new Button();
btn.Text = "点击我";
btn.Click += Btn_Click;
this.Controls.Add(btn);
btn.Location = new Point(10, 10);
}
// 点击按钮事件处理
private void Btn_Click(object sender, EventArgs e)
{
label1.Text = "新的标签内容";
}
}
}