Results 1 to 4 of 4

Thread: Use event handlers in vb.net

  1. #1
    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,

  2. #2
    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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

Similar Threads

  1. Event handlers vs. base class method overrides
    By Tailapa in forum Software Development
    Replies: 5
    Last Post: 26-06-2011, 07:38 PM
  2. How Event Handlers Work together
    By Savannah87 in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 06:44 AM
  3. web.config <handlers>
    By willids in forum Software Development
    Replies: 2
    Last Post: 12-01-2010, 03:50 PM
  4. Event Log Error: Event Source:WinMgmt Event ID:10
    By BlackSunReyes in forum Small Business Server
    Replies: 2
    Last Post: 01-03-2007, 03:27 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,388,379.26521 seconds with 16 queries