What are events
What are events ?
As compared to delegates events works with source and listener methodology. So listeners
who are interested in receiving some events they subscribe to the source. Once this
subscription is done the source raises events to its entire listener when needed. One
source can have multiple listeners.
In sample given below class “ClsWithEvents” is a event source class, which has a event “EventAddString()”. Now the listeners who are interested in receiving this events they can subscribe to this event. In class “FrmWithEvents” you can see they handle clause which is associated with the “mobjClsWithEvents” objects.
Public Class ClsWithEvents Event EventAddString(ByVal Value As String) Public Sub AddString() RaiseEvent EventAddString(“String added by Event”) End Sub End Class Public Class FrmWithEvents Inherits System.Windows.Forms.Form Private WithEvents mobjClsWithEvents As New ClsWithEvents() Private Sub FrmWithEvents_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub mobjClsWithEvents_EventAddString(ByVal Value As String) Handles mobjClsWithEvents.EventAddString LstData.Items.Add(Value) End Sub Private Sub CmdRunEvents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdRunEvents.Click mobjClsWithEvents.AddString() End Sub End Class
Nore:- Above source code is provided in “WindowsEvent”
2007-10-23, 4773👍, 0💬
.NET INTERVIEW QUESTIONS - What is the difference between thread and process? A thread is a path of ...
How To Remove the Top White Space of Your Web Page? - CSS Tutorials - Introduction To CSS Basics The...
What Is C Language? The C programming language is a standardized programming language developed in t...
Can two catch blocks be executed? No, once the proper catch section is executed the control goes fin...
How do we host a WCF service in IIS? Note: - The best to know how to host a WCF in IIS is by doing a...