Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-01-2009
Member
 
Join Date: Jan 2009
Posts: 8
Use event handlers in vb.net

Hello Friend,

I am new in VB.net,
Can anybody knows that How to use event handlers in vb.net?

Any help will appreciated,

Thanks,
Reply With Quote
  #2  
Old 26-01-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Use event handlers in vb.net

.NET lets you add and remove Event Handlers dynamically on the fly. Your code can start and stop handling events at any time during program execution. Also, you can tie the same code (event handler) to multiple events similar to the Handles clause in VB.NET.

The VB.NET AddHandler and RemoveHandler statements allow this behavior. Both statements take two arguments: the name of the event to handle and the name of the procedure that will handle the event.
Reply With Quote
  #3  
Old 26-01-2009
Member
 
Join Date: May 2008
Posts: 2,008
Implementation of an event in vb.net

Events in the .NET Framework are based on the delegate model. Delegates are type-safe Function Pointers or Callbacks. A delegate can reference both static and instance methods.

Implementation of an event is a three-step procedure.
  1. Declare a delegate, if definition is not provided the .Net Framework would provide a default delegate implementation.
  2. Declare the event signature using the Event keyword and Raise the event using the RaiseEvent statement.
  3. Handle the Event by declaring an event receiver, often called an event handler. Which is a subroutine that responds to an event.
Reply With Quote
  #4  
Old 26-01-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Use event handlers in vb.net

One of the most useful capabilities of the OOP Languages is their inbuilt ability to be aware of a large number of events like MouseOver, MouseClick, and so on so that we can write codes to react to any event that we are interested. This is made possible by the rich set of classes that have been built in the .NET Framework

Some example of event handling using Handles clause are,

Code:
Dim withEvents AnEvent as new EventRaised()
Sub EventEgs()
AnEvent.RaiseEvents()
End Sub

Sub AnEvent_EventHandler() Handles AnEvent.EventOne, AnEvent.EventTwo
MsgBox(?Received Event?)
End Sub

Class EventRaised
Public Event EventOne()
Public Event EventTwo()
Sub RaiseEvents()
RaiseEvent EventOne()
RaiseEvent EventTwo()
End Sub
End Class
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Use event handlers in vb.net"
Thread Thread Starter Forum Replies Last Post
Event handlers vs. base class method overrides Tailapa Software Development 5 26-06-2011 07:38 PM
How Event Handlers Work together Savannah87 Software Development 5 06-03-2010 06:44 AM
web.config <handlers> willids Software Development 2 12-01-2010 03:50 PM
Event Log Error: Event Source:WinMgmt Event ID:10 BlackSunReyes Small Business Server 2 01-03-2007 03:27 AM


All times are GMT +5.5. The time now is 07:06 PM.