怎么动态的添加button按钮。。。

道阻且长 2010-09-20 05:28:12
我想定义一个button数组。。然后通过for循环定义button
System.Windows.Forms.Button[] button=new System.Windows.Forms.Button[5];


button[0] = new System.Windows.Forms.Button();
this.SuspendLayout();
button[0].Location = new System.Drawing.Point(31, 35);
button[0].Name = "button[0]";
button[0].Size = new System.Drawing.Size(75, 23);
button[0].TabIndex = 0;
button[0].Text = "button1";
button[0].UseVisualStyleBackColor = true;
this.Controls.Add(button[0]);
但是弄出来的button不能点的。。也不能添加事件
问下要怎么弄。。
...全文
273 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
完美算法 2010-09-20
  • 打赏
  • 举报
回复
private void FrmIntroductions_Load(object sender, EventArgs e)//窗口加载事件
{
System.Windows.Forms.Button[] button=new System.Windows.Forms.Button[5];
button[0] = new System.Windows.Forms.Button();
this.SuspendLayout();
button[0].Location = new System.Drawing.Point(31, 35);
button[0].Name = "button[0]";
button[0].Size = new System.Drawing.Size(75, 23);
button[0].TabIndex = 0;
button[0].Text = "button1";
button[0].UseVisualStyleBackColor = true;
button[0].Click += new EventHandler(button_Click);
this.Controls.Add(button[0]);

private void button_Click(object sender, System.EventArgs e)
{

}
wuyq11 2010-09-20
  • 打赏
  • 举报
回复
button[i].Click += new EventHandler(button_Click);
private void button_Click(object sender, System.EventArgs e)
{
Button btn=sender as Button();
}

sdler 2010-09-20
  • 打赏
  • 举报
回复
这个明显是没有注册事件嘛,因为你没有给这个Button注册个事件,手动创建Button .net是不会自动为你创建的,所以你必须手动的注册事件
道阻且长 2010-09-20
  • 打赏
  • 举报
回复
嗯。。知道了谢谢- -
li88990 2010-09-20
  • 打赏
  • 举报
回复
用JAVASCRIPT写一个脚本事件,循环读取Button ID,并定义window.location指向
jinfengboan 2010-09-20
  • 打赏
  • 举报
回复
同意楼上的楼上
cjh200102 2010-09-20
  • 打赏
  • 举报
回复
楼上正解
边城的刀声 2010-09-20
  • 打赏
  • 举报
回复
能点,你得给他添加事件
button[0].Click+=btnClick

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧