Click here to Skip to main content
15,894,410 members
Articles / Multimedia / GDI+

A Professional Calendar/Agenda View That You Will Use

Rate me:
Please Sign up or sign in to vote.
4.92/5 (350 votes)
27 Aug 2009LGPL35 min read 3.1M   117.1K   683  
An Outlook style calendar view with appointments and all-day events, and multiple day view support.
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace System.Windows.Forms.Calendar
{
    /// <summary>
    /// Implements a basic <see cref="ICalendarSelectableElement"/>
    /// </summary>
    public abstract class CalendarSelectableElement
        : ICalendarSelectableElement
    {
        #region Fields
        private Calendar _calendar;
        private Rectangle _bounds;
        private DateTime _date;
        private bool _selected;
        #endregion

        #region Ctor

        /// <summary>
        /// Creates a new Element
        /// </summary>
        /// <param name="calendar"></param>
        public CalendarSelectableElement(Calendar calendar)
        {
            if (calendar == null) throw new ArgumentNullException("calendar");

            _calendar = calendar;
        }

        #endregion

        #region ICalendarSelectableElement Members

        
        public virtual DateTime Date
        {
            get { return _date; }
        }


        /// <summary>
        /// Gets the Calendar this element belongs to
        /// </summary>
        public virtual Calendar Calendar
        {
            get { return _calendar; }
        }

        /// <summary>
        /// Gets the Bounds of the element on the <see cref="Calendar"/> window
        /// </summary>
        public virtual Rectangle Bounds
        {
            get { return _bounds; }
        }

        /// <summary>
        /// Gets a value indicating if the element is currently selected
        /// </summary>
        public virtual bool Selected
        {
            get
            {
                return _selected;
            }
        }

        /// <summary>
        /// Compares this element with other using date as comparer
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public virtual int CompareTo(ICalendarSelectableElement element)
        {
            return this.Date.CompareTo(element.Date);
        }

        #endregion

        #region Internal Methods

        /// <summary>
        /// Sets the value of the <see cref="Bounds"/> property
        /// </summary>
        /// <param name="bounds">Bounds of the element</param>
        internal virtual void SetBounds(Rectangle bounds)
        {
            _bounds = bounds;
        }

        /// <summary>
        /// Sets the value of the <see cref="Selected"/> property
        /// </summary>
        /// <param name="selected">Value indicating if the element is currently selected</param>
        internal virtual void SetSelected(bool selected)
        {
            _selected = selected;

            //Calendar.Invalidate(Bounds);
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Product Manager
United States United States
- I've been programming Windows and Web apps since 1997.
- My greatest concern nowadays is product, user interface, and usability.
- TypeScript / React expert

@geeksplainer

Comments and Discussions