注册 登录
编程论坛 C# 论坛

请教,button事件

gesongs 发布于 2015-05-25 14:23, 619 次点击
for (int i = 1; i < 6; i++)
                {
                    Button pageBT = new Button();
                    pageBT.Name = i.ToString();
                    pageBT.Text = i.ToString();
                    pageBT.Width = 18;
                    pageBT.Height = 18;
                    pageBT.Cursor = Cursors.Hand;
                    pageBT.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                    pageBT.FlatStyle = FlatStyle.Flat;
                    pageBT.FlatAppearance.BorderSize = 0;  
                    pageBT.Location = new Point(i * 18 +50, 50);
                    pageBT.Click += new System.EventHandler(this.page_Click);
                    this.Controls.Add(pageBT);
               }
private void page_Click(object sender, EventArgs e)
        {
            //这里 如何 实现 点击 动态添加的 button 后 获取 自己的txt值?
         }

如 上述动态 产生  1 2 3 4 动态的 button
然后 点击 1按钮 弹出 1  
     点击 2按钮 弹出 2
     点击 3按钮  弹出 3
.。。。
3 回复
#2
over12302015-05-26 08:35
MessageBox.Show((sender as Button).Text);
#3
wangnannan2015-05-26 10:39
第一种方法 楼上已给出 第二种 反射查找
#4
gesongs2015-05-28 10:41
回复 2楼 over1230
谢谢!
你不早说
我却 整了这出
sender.ToString().Split(',')[1].Split(':')[1];
1