This documentation is archived and is not being maintained.

MonthCalendar.TodayDate Property

Gets or sets the value that is used by MonthCalendar as today's date.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public DateTime TodayDate { get; set; }
/** @property */
public DateTime get_TodayDate ()

/** @property */
public void set_TodayDate (DateTime value)

public function get TodayDate () : DateTime

public function set TodayDate (value : DateTime)

Property Value

A DateTime representing today's date. The default value is the current system date.

Exception typeCondition

ArgumentOutOfRangeException

The value is less than the minimum allowable date.

-or-

The value is greater than the maximum allowable date.

By default, the TodayDate property returns the current system date, and the TodayDateSet property is false. Setting the TodayDate property sets the TodayDateSet property to true and, from that point, the value returned by the TodayDate property is the one the user sets.

The following code example demonstrates how to use the SelectionStart, TodayDate and SelectionEnd properties. To run the example, paste the following code into a form containing a MonthCalendar control named MonthCalendar1, and call the ShowAWeeksVacationOneMonthFromToday method from the form's constructor or Load event-handling method.

// Computes a week one month from today.
private void ShowAWeeksVacationOneMonthFromToday()
{
    System.DateTime today = this.MonthCalendar1.TodayDate;
    int vacationMonth = today.Month + 1;
    int vacationYear = today.Year;

    if (today.Month == 12)
    {
        vacationMonth = 1;
        ++vacationYear;
    }

    // Select the week using SelectionStart and SelectionEnd.
    this.MonthCalendar1.SelectionStart = 
        new System.DateTime(today.Year, vacationMonth, today.Day-1);
    this.MonthCalendar1.SelectionEnd = 
        new System.DateTime(today.Year, vacationMonth, today.Day+6);
}

// Computes a week one month from today.
private void ShowAWeeksVacationOneMonthFromToday()
{
    System.DateTime today = this.monthCalendar1.get_TodayDate();
    int vacationMonth = 1;
    if (today.get_Month() < 12) {
        vacationMonth = today.get_Month() + 1;
    }
    // Select the week using SelectionStart and SelectionEnd.
    this.monthCalendar1.set_SelectionStart(
        new System.DateTime(today.get_Year(),
        vacationMonth, today.get_Day() - 1));
    this.monthCalendar1.set_SelectionEnd(
        new System.DateTime(today.get_Year(),
        vacationMonth, today.get_Day() + 6));
} //ShowAWeeksVacationOneMonthFromToday

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0
Show: