When we double click on an event in a property window internally a method gets generated for writing the code and this method has a special name Event procedure which is block of code i.e bound with an event of control and gets executed whenever an event occurs.
The code written under event procedure will be executed by the event when it occurs taking the help of a delegate.
Whenever the event occurs it will call the delegate which then execute the event procedure that it bound with the event. Because a delegate is responsible for the execution of event procedure first the event,delegate and the event procedure should be bound with each other as following :
Syntax:
<control><event> += new <delegate> (<event proc>)
Example :
this.Load += new EventHandler(Form 3 Load);
Events and delegates are predefined under BCL(evens are defined in control classes and delegates are defined under namespace) what is defined here is only an Event procedure.
After defining a Event procedure in Form class Visual Studio links the Event ,delegate and event procedure.
Note : One delegate can be used by multiple events to execute event procedure but all events will not use the same delegates where different events may use different delegates to execute event procedures.
No comments:
Post a Comment