본문 바로가기
Visual Basic .NET/Event Handler

how to set Event Handler at runtime

by edupicker(체르니) 2008. 6. 24.
How to set Event Handler at runtime?

Not only can you create event handlers at design time, but you can also assign them at run time.
First create the event handler. You must get the routine’s parameters exactly correct for the type of event handler you want to create.
For example, a TextBox control’s TextChanged event handler must take two parameters with types System.Object and System.EventArgs.

syntax :
When you create the Event
AddHandler object'event, AddressOf eventhandler's procedure

And you remove the event
RemoveHandler object'event, AddressOf eventhandler's procedure

Finally, eventhandler's procedure
Public Sub ObjectHandler1(ByVal sender As System.Object, ByVal e As System.EventArgs)
        codes....
End Sub

I attached the project file to undertand this definition.
Programming is exciting.

'Visual Basic .NET > Event Handler' 카테고리의 다른 글

What is the delegate in VB.NET  (0) 2008.07.02