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, 4737👍, 0💬
How To Select Some Rows from a Table? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY If yo...
.NET INTERVIEW QUESTIONS - What are Daemon threads and how can a thread be created as Daemon? Daemon...
How To Use Subqueries with the IN Operator? - MySQL FAQs - SQL SELECT Statements with JOIN and Subqu...
Which bit wise operator is suitable for checking whether a particular bit is on or off? The bitwise ...
Can include files be nested? The answer is yes. Include files can be nested any number of times. As ...