Click here to Skip to main content
14,920,188 members
Articles / Desktop Programming / MFC
Posted 9 Nov 2005


375 bookmarked

Calendar DayView Control

Rate me:
Please Sign up or sign in to vote.
4.86/5 (152 votes)
20 Jun 2006CPOL3 min read
A calendar DayView control.


This article describes creating a day view control for visualizing schedule functions in required applications. I have cloned the Outlook day view appearance for similar use. Here is a screenshot:

Office 12 Theme:

Sample Image

Office XP Theme:

Sample Image


Before writing this control, I was in need of a day view control that just looks like that in Outlook. I have found some commercial toolkits but none of them meets my requirements. Some of those want that all appointments be given before showing the control, some of those are not open source, etc. So I wrote this control in a "hurry development", and I think other people can use it. Pay back time for using the CodeProject :)

What we have?

  • You can create your appointment class to hold special information (other than start, end dates and title).
  • You don't need to read all appointments from the DB or something like that.
  • You can specify how much days will be shown.
  • You can colorize appointments to show different views.
  • In-place editing.
  • Drag drop operations.
  • No Win32 API.
  • Theme based rendering.

By the way, it's compiled under the final release of .NET 2.0. If you don't have it, you need to recompile the project.

Using the code

This control uses a class named "Appointment" to visualize the view. The DayView control doesn't pay attention to saving appointments to the DB or fetching them. So, you need to write your own DB logic and answer the events.

The control implements these events to interact with the hosting application:

  • dayView1.NewAppointment
  • dayView1.ResolveAppointments
  • dayView1.SelectionChanged

The sample application uses a list collection as the container for appointments. You may use a cached DB source too.

NewAppointment event

This is raised when the user wants to create an appointment. Event arguments contain start date, end date, and title values of the new appointment. You can create your appointment class that inherits from the DayView.Appointment base class.

The sample application just creates a new appointment, and adds it to the list collection.

void dayView1_NewAppointment(object sender, NewAppointmentEventArgs args)
    Appointment m_Appointment = new Appointment();

    m_Appointment.StartDate = args.StartDate;
    m_Appointment.EndDate = args.EndDate;
    m_Appointment.Title = args.Title;


ResolveAppointments event

This event is raised when the DayView control needs to show an appointment on a date. Event arguments contain the start date and end date of the required range of dates.

The sample application scans the list collection for a specified date range. You can fetch them from your own DB too.

private void dayView1_ResolveAppointments(object sender, 
                      ResolveAppointmentsEventArgs args)
    List<Appointment> m_Apps = new List<Appointment>();

    foreach (Appointment m_App in m_Appointments)
        if ((m_App.StartDate >= args.StartDate) && 
            (m_App.StartDate <= args.EndDate))

    args.Appointments = m_Apps;

Selection Changed event

This event is raised when the user selects an appointment.

private void dayView1_SelectionChanged(object sender, EventArgs e)
    label3.Text = dayView1.SelectionStart.ToString() + 
                  ":" + dayView1.SelectionEnd.ToString();

The sample application shows the start date and the end date of the selected appointment in a label.

Points of interest

When I wrote this control, the hard part was sorting the appointments on screen without crossing over. The control internally uses an "AppointmentView" class to hold the state of appointments on screen. The rest of the code was drawing and isolating from the external application.

You may see some remarked codes about all-day events, but currently all-day events is not complete. When I finish it, I'll update this article. (Thanks to Claus Espersen for implementing the Office 12 theme and bug fixes.)


  • 14.07.2006
    • Bug fixes.
    • Start hour and start minute properties implemented.
    • Theme based rendering implemented.
    • AllowNew property implemented.
    • Mouse drag drop bugs fixed.
    • Internal changes for all day events.
    • Zoom feature implemented.
  • 11.09.2005
    • Initial release.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ertan Tike
Web Developer
Turkey Turkey
No Biography provided

Comments and Discussions

QuestionRemove Saturday and Sunday Columns Pin
Info service4-Oct-18 19:52
MemberInfo service4-Oct-18 19:52 
QuestionHourWorkStart Pin
Member 1236477528-Mar-18 0:21
MemberMember 1236477528-Mar-18 0:21 
QuestionAnother little glich when mouse over the arrow Forwardbutton Pin
Member 1062646719-Sep-17 10:42
MemberMember 1062646719-Sep-17 10:42 
QuestionBug with FirstDayOfWeek = Monday (on culture "fr-FR") Pin
Member 1062646717-Sep-17 3:38
MemberMember 1062646717-Sep-17 3:38 
QuestionAlarme Pin
mamanes19-Feb-17 11:23
Membermamanes19-Feb-17 11:23 
QuestionPeople instead of days Pin
roc.cos14-Feb-17 12:43
Memberroc.cos14-Feb-17 12:43 
AnswerRe: People instead of days Pin
TrevorWJ19-May-20 13:19
MemberTrevorWJ19-May-20 13:19 
GeneralRe: People instead of days Pin
roc.cos19-May-20 20:08
Memberroc.cos19-May-20 20:08 
GeneralRe: People instead of days Pin
TrevorWJ22-Jun-20 12:42
MemberTrevorWJ22-Jun-20 12:42 
QuestionMove/copy entry to monthCalendar Pin
Member 1030250829-Jan-17 2:59
MemberMember 1030250829-Jan-17 2:59 
QuestionRemoving appointments Pin
Fabio Blardone30-Oct-16 4:49
MemberFabio Blardone30-Oct-16 4:49 
AnswerCalendar dayview with Visual Studio 2015 (Windows Forms) Pin
aluizs17-Apr-16 18:22
Memberaluizs17-Apr-16 18:22 
PraiseThanks Pin
Ranjan.D27-Mar-16 13:46
professionalRanjan.D27-Mar-16 13:46 
QuestionHorizontal Orientation Pin
shazwaz3-Dec-15 20:06
Membershazwaz3-Dec-15 20:06 
Questiondelete appointment Pin
Member 1201672024-Nov-15 23:59
MemberMember 1201672024-Nov-15 23:59 
AnswerRe: delete appointment Pin
Member 1308074013-May-17 2:10
MemberMember 1308074013-May-17 2:10 
QuestionAdding items - No entry appears - Drawing error Pin
Member 114515695-Aug-15 4:13
MemberMember 114515695-Aug-15 4:13 
QuestionThis control has no midnight sector Pin
Giovanni S.30-Jul-15 8:59
MemberGiovanni S.30-Jul-15 8:59 
QuestionAll-Day Event and Events Spanning Multiple Days? Pin
Member 1097564425-Sep-14 2:28
MemberMember 1097564425-Sep-14 2:28 
AnswerRe: All-Day Event and Events Spanning Multiple Days? Pin
Member 1172713416-Jun-17 2:52
MemberMember 1172713416-Jun-17 2:52 
QuestionCalendar shows same appointments every month Pin
pazzokli21-Mar-14 3:41
Memberpazzokli21-Mar-14 3:41 
QuestionMerhaba Pin
Member 1047238618-Dec-13 5:42
MemberMember 1047238618-Dec-13 5:42 
QuestionColumn fixed - show minutes Pin
Member 80596961-Oct-13 4:36
MemberMember 80596961-Oct-13 4:36 
AnswerRe: Column fixed - show minutes Pin
rafaelchefe12-Jun-15 6:56
Memberrafaelchefe12-Jun-15 6:56 
QuestionAppointment change Pin
neo11on23-Aug-13 22:17
Memberneo11on23-Aug-13 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.