今日の日付として MonthCalendar で使用される値を取得または設定します。
名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
'宣言
Public Property TodayDate As DateTime
'使用
Dim instance As MonthCalendar
Dim value As DateTime
value = instance.TodayDate
instance.TodayDate = value
public DateTime TodayDate { get; set; }
public:
property DateTime TodayDate {
DateTime get ();
void set (DateTime value);
}
/** @property */
public DateTime get_TodayDate ()
/** @property */
public void set_TodayDate (DateTime value)
public function get TodayDate () : DateTime
public function set TodayDate (value : DateTime)
プロパティ値
今日の日付を表す DateTime。既定値は、現在のシステム日付です。
例外
例外の種類 | 条件 |
---|---|
値が許容される日付の最小値より小さい値です。 または 値が許容される日付の最大値を超えています。 |
解説
既定では、TodayDate プロパティは現在のシステム日付を返し、TodayDateSet プロパティは false です。TodayDate プロパティを設定すると、TodayDateSet プロパティは true に設定され、その時点から TodayDate プロパティによって返される値はユーザー設定値となります。
使用例
SelectionStart プロパティ、TodayDate プロパティおよび SelectionEnd プロパティを使用する方法を次のコード例に示します。この例を実行するには、次のコードを MonthCalendar1
という名前の MonthCalendar コントロールが配置されているフォームに貼り付けて、フォームのコンストラクタまたは Load イベント処理メソッドから ShowAWeeksVacationOneMonthFromToday
メソッドを呼び出します。
' Computes a week one month from today.
Private Sub ShowAWeeksVacationOneMonthFromToday()
Dim today As Date = monthCalendar1.TodayDate
Dim vacationMonth As Integer = today.Month + 1
Dim vacationYear As Integer = today.Year
If (today.Month = 12) Then
vacationYear += 1
vacationMonth = 1
End If
Me.monthCalendar1.SelectionStart = _
New Date(vacationYear, vacationMonth, today.Day - 1)
Me.monthCalendar1.SelectionEnd = _
New Date(vacationYear, vacationMonth, today.Day + 6)
End Sub
// 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.
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 =
System::DateTime( today.Year, vacationMonth, today.Day - 1 );
this->MonthCalendar1->SelectionEnd =
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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0
参照
関連項目
MonthCalendar クラス
MonthCalendar メンバ
System.Windows.Forms 名前空間
TodayDateSet
MonthCalendar.ShowToday プロパティ