using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnNew_Click(object sender, EventArgs e)
{
MessageBox.Show("button evet");
}
private void Form1_Load(object sender, EventArgs e)
{
//动态创建button
Button btnObject = new Button();
btnObject.Name = "btnNew";
btnObject.Text = "动态创建按钮";
btnObject.Size = new Size(100, 50);
btnObject.Location = new Point(btnObject.Location.X + 100, btnObject.Location.Y + 50);
btnObject.Visible = true;
this.Controls.Add(btnObject);
btnObject.Click += new EventHandler(btnNew_Click);//绑定按钮点击事件
}
}
}
C# 动态创建按钮
最新推荐文章于 2024-04-30 01:52:24 发布