How to use event handlers in vb.net

mohanacs

New member
Joined
Oct 1, 2004
Messages
2
Programming Experience
1-3
Anyone who knows abt how to use eventhandlers and 4 wht purposes in .net pls gve me some code samples or white papers demonstartes those areas.
 

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
We could probably help more if we knew what events you wanted to handle, but in .NET the basic format is:

VB.NET:
Private Sub SubNameCanBeAnything(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonName.Click
   'Code here to handle the button click event
End Sub
Lets walk through the example:
1. Private means that it is only availalbe to the Class that it is in.
2. Sub means that it is a Subroutine
3. SubNameCanBeAnything is the sub name (can be anything, but it should be descriptive of what it does such as btnName_Click)
4. ByVal sender as System.Object is the first argument for all .NET event arguments
5. ByVal e as System.EventArgs is the second argument for all .NET event arguments (sometimes the as System.EventArgs needs to be a more specific Event Argument Typp)
6. Handles btnName.Click tells .NET what event this subroutine handles. Also one subroutine can handle more than just one event (eg: Handles btn1.Click, btn2.Click)

If you need more specific help, again please tell us what sort of event you are wanting to handle and we can answer with more specifics.
 
Top Bottom