MonthCalendar.TodayDate Property

Definition

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

C#
public DateTime TodayDate { get; set; }

Property Value

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

Exceptions

The value is less than the minimum allowable date.

-or-

The value is greater than the maximum allowable date.

Examples

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.

C#
// Computes a week one month from today.
private void ShowAWeeksVacationOneMonthFromToday()
{
    DateTime today = this.MonthCalendar1.TodayDate;
    DateTime vacationStart = today.AddMonths(1);
    DateTime vacationEnd = vacationStart.AddDays(7);

    // Select the week using SelectionStart and SelectionEnd.
    this.MonthCalendar1.SelectionStart = vacationStart.AddDays(-1);
    this.MonthCalendar1.SelectionEnd = vacationEnd.AddDays(-1);
}

Remarks

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.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also