说我有,我动态创建一个对象。例如,假设我创建了一个名为用作MyButton按钮:
Say I have an object that I dynamically create. For example, say I create a button called "MyButton":
Dim MyButton as New Button()
MyButton.Name = "MyButton"
如何创建,也就是说,一个Click事件?如果它是静态创建的,我可以创建一个函数为:
How do I create, say, a "Click" event? If it were statically created I could create a function as:
Private Sub MyButton_Click(ByVal sender as system.object, ByVal e As System.EventArgs) Handles....
如何实现的事件处理程序用作MyButton?
How do I implement an event handler for MyButton?
您使用的AddHandler
和 AddressOf
这样的
Dim MyButton as New Button()
MyButton.Name = "MyButton"
AddHandler MyButton.Click, AddressOf MyButton_Click
还有更多的信息在这里MSDN文档中:
There is more info here in the MSDN documentation:
如何添加事件处理器使用code