在collectionBase中创建期间在按钮中添加事件 [英] Adding Events in buttons during creation in collectionBase
本文介绍了在collectionBase中创建期间在按钮中添加事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public Button this[int index]
{
get
{
return (Button)List[index];
}
}
我无法弄清楚在调用此方法时如何在创建过程中向按钮添加事件.
请帮忙,谢谢.:)
i cannot figure out how to add events to a button during creation when this method is invoked.
please help thank you.:)
推荐答案
你好
将其添加到构造函数中.创建一个继承自Button
的新类
Hello
Add it in the Constructor. Create a new class that inherits from Button
public class MyButton : System.Windows.Forms.Button
{
public MyButton()
{
this.Click += new EventHandler(MyButton_Click);
}
void MyButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello");//it's a sample
}
}
我当然喜欢:
Of course I like it:
public class MyButton : System.Windows.Forms.Button
{
public MyButton()
{
this.Click += new EventHandler(
(object sender, EventArgs e) =>
{
MessageBox.Show("Hello");//It's a sample...
});
}
}
在这里看看:
如何:使用代码添加事件处理程序 [ CSharp中的事件处理 [
Take a look here:
How to: Add an Event Hadler Using Code[^]
Event Handling in CSharp[^]
这篇关于在collectionBase中创建期间在按钮中添加事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文