Events in dot net pogramming, DOT NET Programming

What are events?

As compared to the delegates events works with source and listener methodology. So the listeners who are interested in receiving few events they subscribe to the source. Once this subscription is completed the source raises events to its entire listener when required. One source can have many listeners. In the sample given below class "ClsWithEvents" is an event source class, which has a event "EventAddString()". Now the listeners who are interested in receiving these events they can subscribe to this event. In the 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

2484_Event.png

Figure:-Events in action

Posted Date: 9/22/2012 3:03:28 AM | Location : United States







Related Discussions:- Events in dot net pogramming, Assignment Help, Ask Question on Events in dot net pogramming, Get Answer, Expert's Help, Events in dot net pogramming Discussions

Write discussion on Events in dot net pogramming
Your posts are moderated
Related Questions
Question: (a) Explain the Postback process as use with Web Forms. (b) Write extract codes to demonstrate how to store and retrieve values in: (i) a Session Object (ii)

The Cache object is always defined in the System.Web.Caching namespace. You can get the reference to the Cache object by either using the Cache property of the HttpContext class in

What is the namespace in which .NET have the data functionality classes? System.data : This namespace contains the basic objects used for accessing &  storing relational d

What are the differences between AJAX and JavaScript? The differences among AJAX and JavaScript are given as follows: AJAX sends request to the server and does not wait for

What is lazy initialization? Lazy initialization is a process by which an object is not initialized until it is first called in your code. The .NET 4.0 introduces a new wrapper

Briefly explain the characteristics of reference-type variables that are supported in the C# programming language. The variables that are based on reference types keeps referen

What's difference between Datagrid, Datalist and repeater? The Datalist ,Datagrid, and Repeater are all ASP.NET data Web controls. They have many things in common such as Da

What are shared (VB.NET)/Static(C#) variables? Shared/Static classes are used when a class gives functionality which is not specific to any instance. In brief if you want an ob

Converting $ into Rs.  - C# Program I am a learner of C# language and i am struggling with how to convert $ into Rs. in C#. Can you have any code examples for this?

Construct a .NET wrapper for a C++ Dll - repost Project Description: We have a classic VC++ Dll (source code of DLL not required) that requires a .NET wrapper built by you. U