Export (0) Print
Expand All

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 Value

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

ExceptionCondition
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);
	}
The following code example demonstrates how to use the MonthCalendar.SelectionStart and MonthCalendar.SelectionEnd properties.
To run the example, paste the following code in a form containing a MonthCalendar control named MonthCalendar1 and call the

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft