Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is an event handler?

I need to know the meaning of this code:
VB
Dim entryValue As TextBox = CType(e.Control, TextBox)
AddHandler entryValue.KeyPress
Posted
Updated 14-Sep-12 0:26am
v3

event handler is responsible for call related method when event occur
suppose we want to do something when key-pressed in textbox
so,add handler for keypress event
VB
dim txt as new Textbox
AddHandler txt.KeyPress, AddressOf txt_KeyPress

VB
Private Sub txt_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 
...
End sub



read this article will help you
http://blackwasp.co.uk/CSharpEventAccessors.aspx[^]

Happy coding!
:)
 
Share this answer
 
v3
Comments
_Amy 14-Sep-12 6:35am    
Deserves 5'ed! :)
Aarti Meswania 14-Sep-12 6:37am    
thank you! :)
An event handler is a routine that handles an event.

The easiest event to understand is the button press event, if you insert a button into a dialog, then you will want to react to the event of pressing that button.

The event handler (typically added from the dialog editor or the class wizard) will take care of that event and using it's parameters allow the programmer to filter and process what is needed to be handled in that event.

in pseudocode:
OnBtnClick()
{
  MessageBox("you have pressed the button");
}


Take a look at this wikipedia article[^] which explains it very well (from the event itself to the event handler).

Good luck!
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900