Events and delegates in C# Part 108

  • دعنا نشارك هذا :
ترتيب الدرس : 108
المدة : 00:14:57
التحكم :
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/01/events-and-delegates-in-c-part-108.html

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation1

Slides
http://csharp-video-tutorials.blogspot.com/2013/08/part-108-events-and-delegates-in-c.html

All ASP .NET Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-aspnet-video-tutorial.html

All ASP .NET Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-slides.html

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view1&sortdd

All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists

In this video we will discuss about raising another custom event from CalendarUserControl. If you have not watched Parts 106 and 107, I would strongly encourage you to do so before continuing with this video. In this part, we will discuss about raising DateSelected custom event, whenever, the user selects a "Date" from the "CalendarUserControl".

The following are the steps to raise this event
Step 1: Create "DateSelectedEventArgs" class that will contain the event data.
public class DateSelectedEventArgs : EventArgs
{
private DateTime _selectedDate;

public DateSelectedEventArgs(DateTime selectedDate)
{
this._selectedDateselectedDate;
}

public DateTime SelectedDate
{
get
{
return this._selectedDate;
}
}
}

Step 2: Create DateSelectedEventHandler delegate.
public delegate void DateSelectedEventHandler(object sender, DateSelectedEventArgs e);

Step 3: Create DateSelected event.
public event DateSelectedEventHandler DateSelected;

Step 4: Create a protected virtual method "OnDateSelection" to raise the event.
protected virtual void OnDateSelection(DateSelectedEventArgs e)
{
if (DateSelected ! null)
{
DateSelected(this, e);
}
}

Step 5: Finally raise the event, whenever a date is selected from the CalendarUserControl.
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
txtDate.TextCalendar1.SelectedDate.ToShortDateString();
DateSelectedEventArgs dateSelectedEventDatanew DateSelectedEventArgs(Calendar1.SelectedDate);
OnDateSelection(dateSelectedEventData);

// Rest of the code
}

For the HTML and code samples used in the demo please visit my blog at the following link
http://csharp-video-tutorials.blogspot.com/2013/01/events-and-delegates-in-c-part-108.html

سيتم تفعيل التعليقات قريبا

y
Sep 23, 2020 07:32:26
youtube