/* Copyright 2012 Justin LeCheminant This file is part of WindowsFormsCalendar. indowsFormsCalendar is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. indowsFormsCalendar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with indowsFormsCalendar. If not, see . */ using System; using System.Collections.Generic; using System.Text; using System.Drawing; namespace WindowsFormsCalendar { /// /// Represents a week displayed on the /// public class CalendarWeek { #region Events #endregion #region Fields private Rectangle _bounds; private Calendar _calendar; private DateTime _firstDay; #endregion #region Properties /// /// Gets the bounds of the week /// public Rectangle Bounds { get { return _bounds; } } /// /// Gets the calendar this week belongs to /// public Calendar Calendar { get { return _calendar; } } /// /// Gets the bounds of the week header /// public Rectangle HeaderBounds { get { return new Rectangle( Bounds.Left, Bounds.Top + Calendar.Renderer.DayHeaderHeight, Calendar.Renderer.WeekHeaderWidth, Bounds.Height - Calendar.Renderer.DayHeaderHeight ); } } /// /// Gets the sunday that starts the week /// public DateTime StartDate { get { return _firstDay; } } #endregion /// /// Initializes a new instance of the class. /// /// The calendar. /// The first day. internal CalendarWeek(Calendar calendar, DateTime firstDay) { _calendar = calendar; _firstDay = firstDay; } #region Public Methods /// /// Gets the short version of week's string representation /// /// public string ToStringShort() { DateTime saturday = StartDate.AddDays(6); if (saturday.Month != StartDate.Month) { return string.Format("{0} - {1}", StartDate.ToString("d/M"), saturday.ToString("d/M") ); } else { return string.Format("{0} - {1}", StartDate.Day, saturday.ToString("d/M") ); } } /// /// Gets the large version of string representation /// /// The week in a string format public string ToStringLarge() { DateTime saturday = StartDate.AddDays(6); if (saturday.Month != StartDate.Month) { return string.Format("{0} - {1}", StartDate.ToString("d MMM"), saturday.ToString("d MMM") ); } else { return string.Format("{0} - {1}", StartDate.Day, saturday.ToString("d MMM") ); } } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { return ToStringLarge(); } #endregion #region Private Methods /// /// Sets the value of the property /// /// internal void SetBounds(Rectangle r) { _bounds = r; } #endregion } }