public partial class Form1 : Form
{
private static int x=50;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Button btn = new Button();
btn.Text = DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
btn.Name = btn.Text;
btn.Click+=new EventHandler(button1_Click);//事件委托,所有的按钮都执行的是
button1_Click事件。
btn.Height = 30;
btn.Width = 100;
btn.Left = 100;
btn.Top = x;
btn.Show();
this.Controls.Add(btn);
this.Refresh();
x += 50;
}
}
.net WinForm动态添加控件和事件
最新推荐文章于 2023-03-31 21:09:17 发布