Click here to Skip to main content
Licence CPOL
First Posted 9 Nov 2005
Views 635,229
Downloads 4,880
Bookmarked 345 times

Calendar DayView Control

By Ertan Tike | 20 Jun 2006
A calendar DayView control.
2 votes, 1.5%
1
1 vote, 0.7%
2
1 vote, 0.7%
3
16 votes, 11.9%
4
114 votes, 85.1%
5
4.85/5 - 134 votes
3 removed
μ 4.71, σa 1.09 [?]

Introduction

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

Background

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;

    m_Appointments.Add(m_Appointment);
}

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))
            m_Apps.Add(m_App);

    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.)

History

  • 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.

License

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

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionproblem saving appointment Pinmemberremert6922:05 8 Feb '12  
QuestionDelete NewAppointment? PinmemberPato de Borracfha2:57 23 Oct '11  
QuestionWeb control PinmemberPrincVenu23:21 10 Oct '11  
QuestionNice One PinmemberSaqlain Raza5:41 7 Oct '11  
GeneralMy vote of 3 Pinmemberbuyong21:34 26 Sep '11  
NewsAppointmentID is back Pinmembernt23829:10 29 Aug '11  
NewsMark more then one day in the calender Pinmembernt23829:02 29 Aug '11  
NewsGrip on a wrong position [modified] Pinmembernt23823:06 27 Aug '11  
BugI have a small bug PinmemberWilltwinny13:57 28 Jul '11  
QuestionUsing With Database PinmemberMehmet Yılmaz Yılmaz6:52 14 Jul '11  
GeneralPopulating the control PinmemberMember 79015260:32 9 May '11  
Generaldatebase problem i need help Pinmemberosman osmanssson8:35 8 May '11  
GeneralProblem: X displayed PinmemberCucca779:00 28 Apr '11  
GeneralFont, BackColor, Padding PinmemberKonrad841:09 20 Apr '11  
GeneralAll Day Events PinmemberNicoel10:26 18 Apr '11  
QuestionAmazing work... PinmemberDavidSavage12:55 9 Mar '11  
GeneralLatest version Pinmemberalgreat1:49 25 Jan '11  
GeneralRe: Latest version Pinmemberkiloolik18:30 20 Mar '11  
GeneralBig problem with appointment rendering Pinmemberlbarciko21:36 16 Dec '10  
GeneralAbsolutely brilliant PinmemberVidhu Jain6:01 2 Dec '10  
QuestionHow to test Appointment exist Pinmemberhoangsamac1:38 12 Oct '10  
QuestionHow to test Appointment exist ? please help me. Pinmemberhoangsamac1:37 12 Oct '10  
GeneralMy vote of 5 PinmemberLance.Zhang21:51 18 Aug '10  
GeneralNeed Printing help Pinmembermindserve1:34 16 Aug '10  
GeneralPrinting Pinmembermindserve2:31 5 Aug '10  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120209.1 | Last Updated 20 Jun 2006
Article Copyright 2005 by Ertan Tike
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid