C#关于给动态添加的按钮绑定事件

private void treeView_Apps_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (MessageBox.Show("确定要安装此APP吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
//MessageBox.Show("1234");
if (e.Node.Tag is App)
{
treeView1.SelectedNode = e.Node;
App app = e.Node.Tag as App;
Button a = new Button();
this.flowLayoutPanel1.Controls.Add(a);
a.Text = app.AppName;
a.Tag = app.AppAddress;
a.MouseClick += new MouseEventHandler(botton_MouseClick);
a.Size = new System.Drawing.Size(66, 66);
a.UseVisualStyleBackColor = true;
}
}
}
private void botton_MouseClick(object sender, MouseEventArgs e)
{

}

这是部分代码,上面的代码是一个动态添加botton的事件,然后给botton绑定一个点击事件,下面的事件想要用到上面的botton的一些属性,该怎么弄啊,不会了,求大神

先在这个类里面 加一个数组
public Data[] btsptmp = new Data[20];
//下面是代码
Button button = new Button(); //新建一个按钮
button.Height = 85;
button.Width = 85;
button.Text = "你猜";//以上是参数
button.MouseClick += new MouseEventHandler(button_MouseClick);//绑定点击事件
btsptmp[i] = new Data //这里是我新建了一个静态构造函数 存储每个按钮的数据方便后期调用
{
lstime = i,
button = button//把新建的按钮存进去
};
flowLayoutPanel1.Controls.Add(button);//在窗口添加按钮
//下面是构造函数类
[Serializable]
public class Data
{
public int lstime;
public Button button;
}
//下面是点击事件
private void button_MouseClick(object sender, MouseEventArgs e){写你需要的事件}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-05-07
private void botton_MouseClick(object sender, MouseEventArgs e)
{
botton b =(botton)sender;
}
sender代表发生事件的对象。追问

没看懂,请原谅我,我是小白

本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网