Click here to Skip to main content
15,891,409 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   117K   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
{
    public class MonthViewDay
    {
        #region Fields

        Rectangle _bounds;
        private DateTime _date;
        private MonthViewMonth _month;
        private MonthView _monthView;

        #endregion

        #region Ctor

        internal MonthViewDay(MonthViewMonth month, DateTime date)
        {
            _month = month;
            _monthView = month.MonthView;
            _date = date;

            
        }

        #endregion

        #region Props

        /// <summary>
        /// Gets the parent MonthView
        /// </summary>
        public MonthView MonthView
        {
            get { return _monthView; }
            set { _monthView = value; }
        }

        /// <summary>
        /// Gets the parent MonthViewMonth
        /// </summary>
        public MonthViewMonth Month
        {
            get { return _month; }
        }

        /// <summary>
        /// Gets the bounds of the day
        /// </summary>
        public Rectangle Bounds
        {
            get { return _bounds; }
        }

        /// <summary>
        /// Gets the date this day represents
        /// </summary>
        public DateTime Date
        {
            get { return _date; }
        }

        /// <summary>
        /// Gets or sets if the day is currently selected
        /// </summary>
        public bool Selected
        {
            get { return Date >= MonthView.SelectionStart && Date <= MonthView.SelectionEnd; }
        }

        /// <summary>
        /// Gets if the day is grayed
        /// </summary>
        public bool Grayed
        {
            get { return Month.Date.Month != Date.Month; }
        }

        /// <summary>
        /// Gets a value indicating if the day instance is visible on the calendar
        /// </summary>
        public bool Visible
        {
            get 
            { 
                return !(Grayed && (Date > MonthView.ViewStart && Date < MonthView.ViewEnd));
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Sets the value of the <see cref="Bounds"/> property
        /// </summary>
        /// <param name="bounds"></param>
        internal void SetBounds(Rectangle bounds)
        {
            _bounds = 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