パブリック イベント| 名前 | 説明 | |
|---|---|---|
| DataBinding | サーバー コントロールがデータ ソースに連結すると発生します。 ( Control から継承されます。) |
| Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。 ( Control から継承されます。) |
| Init | サーバー コントロールが初期化されると発生します。これは、サーバー コントロールの有効期間における最初の手順です。 ( Control から継承されます。) |
| Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。 ( Control から継承されます。) |
| PreRender | Control オブジェクトの読み込み後、表示を開始する前に発生します。 ( Control から継承されます。) |
| SelectionChanged | Calendar コントロール内でユーザーが日、週、または月を選択するたびに発生します。 |
| Unload | サーバー コントロールがメモリからアンロードされると発生します。 ( Control から継承されます。) |
参照
パブリック イベント| 名前 | 説明 | |
|---|---|---|
| DataBinding | サーバー コントロールがデータ ソースに連結すると発生します。 ( Control から継承されます。) |
| DayRender | 各日付が Calendar コントロールのコントロール階層で作成されると発生します。 |
| Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。 ( Control から継承されます。) |
| Init | サーバー コントロールが初期化されると発生します。これは、サーバー コントロールの有効期間における最初の手順です。 ( Control から継承されます。) |
| Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。 ( Control から継承されます。) |
| PreRender | Control オブジェクトの読み込み後、表示を開始する前に発生します。 ( Control から継承されます。) |
| SelectionChanged | ユーザーが日付セレクタ コントロールをクリックして 1 つの日付、1 つの週、または 1 つの月を選択したときに発生します。 |
| Unload | サーバー コントロールがメモリからアンロードされると発生します。 ( Control から継承されます。) |
| VisibleMonthChanged | ユーザーがタイトル見出しの前後の月へのナビゲーション コントロールをクリックしたときに発生します。 |
参照
構文<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public MustInherit Class Calendar Implements ICloneable
解説暦は、週、月、年などの単位に時間を分割します。区分の数、長さ、および開始点は、暦ごとに異なります。
あらゆる瞬間を、特定の暦を使用して一連の数値で表すことができます。たとえば、グレゴリオ暦の紀元 1999 年 3 月 20 日の 8:46:00:0.0 に発生した春分を (1999, 3, 20, 8, 46, 0, 0.0) のように表すことができます。Calendar の実装は、特定の暦の範囲内の任意の日付を類似の一連の数値に割り当てることができます。また、DateTime は、Calendar と DateTimeFormatInfo から得られる情報を使用して、その一連の数値をテキスト表現に割り当てることができます。テキスト表現は、カルチャに依存するものもあれば (たとえば、英語 (米国) カルチャの "8:46 AM March 20th 1999 AD")、カルチャ非依存のものもあります (たとえば、ISO 8601 形式の "1999-03-20T08:46:00")。
Calendar 実装は、1 つ以上の時代 (年号) を定義できます。Calendar クラスは、現在の時代 (年号) (CurrentEra) の値が 0 の場合、列挙整数として時代 (年号) を識別します。
地球が実際に太陽の周りを回る時間と暦年との差、または月が実際に地球の周りを回る時間と暦年との差を埋めるために、閏年の日数は標準の暦年の日数と異なっています。各 Calendar の実装では、閏年の定義が異なります。
一貫性のために、各間隔 (たとえば、最初の月) の最初の単位には、値 1 が割り当てられます。
System.Globalization 名前空間には、GregorianCalendar、HebrewCalendar、HijriCalendar、JapaneseCalendar、JulianCalendar、KoreanCalendar、TaiwanCalendar、ThaiBuddhistCalendar など、Calendar 実装があります。
使用例Imports System Imports System.Globalization Public Class SamplesCalendar Public Shared Sub Main() ' Sets a DateTime to April 3, 2002 of the Gregorian calendar. Dim myDT As New DateTime(2002, 4, 3, New GregorianCalendar()) ' Uses the default calendar of the InvariantCulture. Dim myCal As Calendar = CultureInfo.InvariantCulture.Calendar ' Displays the values of the DateTime. Console.WriteLine("April 3, 2002 of the Gregorian calendar:") DisplayValues(myCal, myDT) ' Adds 5 to every component of the DateTime. myDT = myCal.AddYears(myDT, 5) myDT = myCal.AddMonths(myDT, 5) myDT = myCal.AddWeeks(myDT, 5) myDT = myCal.AddDays(myDT, 5) myDT = myCal.AddHours(myDT, 5) myDT = myCal.AddMinutes(myDT, 5) myDT = myCal.AddSeconds(myDT, 5) myDT = myCal.AddMilliseconds(myDT, 5) ' Displays the values of the DateTime. Console.WriteLine("After adding 5 to each component of the DateTime:") DisplayValues(myCal, myDT) End Sub 'Main Public Shared Sub DisplayValues(myCal As Calendar, myDT As DateTime) Console.WriteLine(" Era: {0}", myCal.GetEra(myDT)) Console.WriteLine(" Year: {0}", myCal.GetYear(myDT)) Console.WriteLine(" Month: {0}", myCal.GetMonth(myDT)) Console.WriteLine(" DayOfYear: {0}", myCal.GetDayOfYear(myDT)) Console.WriteLine(" DayOfMonth: {0}", myCal.GetDayOfMonth(myDT)) Console.WriteLine(" DayOfWeek: {0}", myCal.GetDayOfWeek(myDT)) Console.WriteLine(" Hour: {0}", myCal.GetHour(myDT)) Console.WriteLine(" Minute: {0}", myCal.GetMinute(myDT)) Console.WriteLine(" Second: {0}", myCal.GetSecond(myDT)) Console.WriteLine(" Milliseconds: {0}", myCal.GetMilliseconds(myDT)) Console.WriteLine() End Sub 'DisplayValues End Class 'SamplesCalendar 'This code produces the following output. ' 'April 3, 2002 of the Gregorian calendar: ' Era: 1 ' Year: 2002 ' Month: 4 ' DayOfYear: 93 ' DayOfMonth: 3 ' DayOfWeek: Wednesday ' Hour: 0 ' Minute: 0 ' Second: 0 ' Milliseconds: 0 ' 'After adding 5 to each component of the DateTime: ' Era: 1 ' Year: 2007 ' Month: 10 ' DayOfYear: 286 ' DayOfMonth: 13 ' DayOfWeek: Saturday ' Hour: 5 ' Minute: 5 ' Second: 5 ' Milliseconds: 5
using System; using System.Globalization; public class SamplesCalendar { public static void Main() { // Sets a DateTime to April 3, 2002 of the Gregorian calendar. DateTime myDT = new DateTime( 2002, 4, 3, new GregorianCalendar() ); // Uses the default calendar of the InvariantCulture. Calendar myCal = CultureInfo.InvariantCulture.Calendar; // Displays the values of the DateTime. Console.WriteLine( "April 3, 2002 of the Gregorian calendar:" ); DisplayValues( myCal, myDT ); // Adds 5 to every component of the DateTime. myDT = myCal.AddYears( myDT, 5 ); myDT = myCal.AddMonths( myDT, 5 ); myDT = myCal.AddWeeks( myDT, 5 ); myDT = myCal.AddDays( myDT, 5 ); myDT = myCal.AddHours( myDT, 5 ); myDT = myCal.AddMinutes( myDT, 5 ); myDT = myCal.AddSeconds( myDT, 5 ); myDT = myCal.AddMilliseconds( myDT, 5 ); // Displays the values of the DateTime. Console.WriteLine( "After adding 5 to each component of the DateTime:" ); DisplayValues( myCal, myDT ); } public static void DisplayValues( Calendar myCal, DateTime myDT ) { Console.WriteLine( " Era: {0}", myCal.GetEra( myDT ) ); Console.WriteLine( " Year: {0}", myCal.GetYear( myDT ) ); Console.WriteLine( " Month: {0}", myCal.GetMonth( myDT ) ); Console.WriteLine( " DayOfYear: {0}", myCal.GetDayOfYear( myDT ) ); Console.WriteLine( " DayOfMonth: {0}", myCal.GetDayOfMonth( myDT ) ); Console.WriteLine( " DayOfWeek: {0}", myCal.GetDayOfWeek( myDT ) ); Console.WriteLine( " Hour: {0}", myCal.GetHour( myDT ) ); Console.WriteLine( " Minute: {0}", myCal.GetMinute( myDT ) ); Console.WriteLine( " Second: {0}", myCal.GetSecond( myDT ) ); Console.WriteLine( " Milliseconds: {0}", myCal.GetMilliseconds( myDT ) ); Console.WriteLine(); } } /* This code produces the following output. April 3, 2002 of the Gregorian calendar: Era: 1 Year: 2002 Month: 4 DayOfYear: 93 DayOfMonth: 3 DayOfWeek: Wednesday Hour: 0 Minute: 0 Second: 0 Milliseconds: 0 After adding 5 to each component of the DateTime: Era: 1 Year: 2007 Month: 10 DayOfYear: 286 DayOfMonth: 13 DayOfWeek: Saturday Hour: 5 Minute: 5 Second: 5 Milliseconds: 5 */
using namespace System; using namespace System::Globalization; void DisplayValues( Calendar^ myCal, DateTime myDT ) { Console::WriteLine( " Era: {0}", myCal->GetEra( myDT ) ); Console::WriteLine( " Year: {0}", myCal->GetYear( myDT ) ); Console::WriteLine( " Month: {0}", myCal->GetMonth( myDT ) ); Console::WriteLine( " DayOfYear: {0}", myCal->GetDayOfYear( myDT ) ); Console::WriteLine( " DayOfMonth: {0}", myCal->GetDayOfMonth( myDT ) ); Console::WriteLine( " DayOfWeek: {0}", myCal->GetDayOfWeek( myDT ) ); Console::WriteLine( " Hour: {0}", myCal->GetHour( myDT ) ); Console::WriteLine( " Minute: {0}", myCal->GetMinute( myDT ) ); Console::WriteLine( " Second: {0}", myCal->GetSecond( myDT ) ); Console::WriteLine( " Milliseconds: {0}", myCal->GetMilliseconds( myDT ) ); Console::WriteLine(); } int main() { // Sets a DateTime to April 3, 2002 of the Gregorian calendar. DateTime myDT = DateTime(2002,4,3,gcnew GregorianCalendar); // Uses the default calendar of the InvariantCulture. Calendar^ myCal = CultureInfo::InvariantCulture->Calendar; // Displays the values of the DateTime. Console::WriteLine( "April 3, 2002 of the Gregorian calendar:" ); DisplayValues( myCal, myDT ); // Adds 5 to every component of the DateTime. myDT = myCal->AddYears( myDT, 5 ); myDT = myCal->AddMonths( myDT, 5 ); myDT = myCal->AddWeeks( myDT, 5 ); myDT = myCal->AddDays( myDT, 5 ); myDT = myCal->AddHours( myDT, 5 ); myDT = myCal->AddMinutes( myDT, 5 ); myDT = myCal->AddSeconds( myDT, 5 ); myDT = myCal->AddMilliseconds( myDT, 5 ); // Displays the values of the DateTime. Console::WriteLine( "After adding 5 to each component of the DateTime:" ); DisplayValues( myCal, myDT ); } /* This code produces the following output. April 3, 2002 of the Gregorian calendar: Era: 1 Year: 2002 Month: 4 DayOfYear: 93 DayOfMonth: 3 DayOfWeek: Wednesday Hour: 0 Minute: 0 Second: 0 Milliseconds: 0 After adding 5 to each component of the DateTime: Era: 1 Year: 2007 Month: 10 DayOfYear: 286 DayOfMonth: 13 DayOfWeek: Saturday Hour: 5 Minute: 5 Second: 5 Milliseconds: 5 */
import System.* ; import System.Globalization.* ; public class SamplesCalendar { public static void main(String[] args) { // Sets a DateTime to April 3, 2002 of the Gregorian calendar. DateTime myDT = new DateTime(2002, 4, 3, new GregorianCalendar()); // Uses the default calendar of the InvariantCulture. Calendar myCal = CultureInfo.get_InvariantCulture().get_Calendar(); // Displays the values of the DateTime. Console.WriteLine("April 3, 2002 of the Gregorian calendar:"); DisplayValues(myCal, myDT); // Adds 5 to every component of the DateTime. myDT = myCal.AddYears(myDT, 5); myDT = myCal.AddMonths(myDT, 5); myDT = myCal.AddWeeks(myDT, 5); myDT = myCal.AddDays(myDT, 5); myDT = myCal.AddHours(myDT, 5); myDT = myCal.AddMinutes(myDT, 5); myDT = myCal.AddSeconds(myDT, 5); myDT = myCal.AddMilliseconds(myDT, 5); // Displays the values of the DateTime. Console.WriteLine("After adding 5 to each component of the DateTime:"); DisplayValues(myCal, myDT); } //main public static void DisplayValues(Calendar myCal, DateTime myDT) { Console.WriteLine(" Era: {0}", System.Convert.ToString(myCal.GetEra(myDT))); Console.WriteLine(" Year: {0}", System.Convert.ToString(myCal.GetYear(myDT))); Console.WriteLine(" Month: {0}", System.Convert.ToString(myCal.GetMonth(myDT))); Console.WriteLine(" DayOfYear: {0}", System.Convert.ToString(myCal.GetDayOfYear(myDT))); Console.WriteLine(" DayOfMonth: {0}", System.Convert.ToString(myCal.GetDayOfMonth(myDT))); Console.WriteLine(" DayOfWeek: {0}", System.Convert.ToString(myCal.GetDayOfWeek(myDT))); Console.WriteLine(" Hour: {0}", System.Convert.ToString(myCal.GetHour(myDT))); Console.WriteLine(" Minute: {0}", System.Convert.ToString(myCal.GetMinute(myDT))); Console.WriteLine(" Second: {0}", System.Convert.ToString(myCal.GetSecond(myDT))); Console.WriteLine(" Milliseconds: {0}", System.Convert.ToString(myCal.GetMilliseconds(myDT))); Console.WriteLine(); } //DisplayValues } //SamplesCalendar /* This code produces the following output. April 3, 2002 of the Gregorian calendar: Era: 1 Year: 2002 Month: 4 DayOfYear: 93 DayOfMonth: 3 DayOfWeek: Wednesday Hour: 0 Minute: 0 Second: 0 Milliseconds: 0 After adding 5 to each component of the DateTime: Era: 1 Year: 2007 Month: 10 DayOfYear: 286 DayOfMonth: 13 DayOfWeek: Saturday Hour: 5 Minute: 5 Second: 5 Milliseconds: 5 */
継承階層
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照
構文
解説カレンダーの表示単位は、日、週、月です。モバイル デバイスに 1 か月分をすべてレンダリングできるかどうかは、そのデバイスの機能によって異なります。通常、Calendar コントロールでは日付を 1 つ選択できます。
モバイル Calendar コントロールは、Web フォーム Calendar コントロールをラップします。モバイル Calendar コントロールには、基になるコントロールのプロパティ、メソッド、およびイベントと同じものもありますが、HTML レンダリング固有のプロパティは公開しません。これらのプロパティなどを変更するには、WebCalendar プロパティ経由で基になるコントロールにアクセスし、直接、設定を変更します。
使用例次のコード例には、ページの読み込みコード ブロックに SelectionMode プロパティを記述して、日、週、月ごとに期間を選択する方法が示されています。この例では、Calendar クラスの BorderStyle プロパティおよび BackColor プロパティを設定し、ユーザーの選択を識別します。
メモ |
|---|
| 次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" Inherits="System.Web.UI.MobileControls.MobilePage" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load ' Display the day header Calendar1.ShowDayHeader = True ' Allow the user to select a week or a month at a time. Calendar1.SelectionMode = _ CalendarSelectionMode.DayWeekMonth ' Set the BorderStyle and BorderColor properties. Calendar1.WebCalendar.DayStyle.BorderStyle = _ BorderStyle.Solid Calendar1.WebCalendar.DayStyle.BorderColor = Color.Cyan Calendar1.CalendarEntryText = "Your birthdate" Calendar1.FirstDayOfWeek = _ System.Web.UI.WebControls.FirstDayOfWeek.Friday Calendar1.VisibleDate = DateTime.Parse("7/1/2004") End Sub Protected Sub ShowChanges(ByVal sender As Object, _ ByVal e As EventArgs) TextView1.Text = "The date you selected is " & _ Calendar1.SelectedDate.ToShortDateString() ' Distinguish the selected block using colors. Calendar1.WebCalendar.SelectedDayStyle.BackColor = _ Color.LightGreen Calendar1.WebCalendar.SelectedDayStyle.BorderColor = _ Color.Gray Calendar1.WebCalendar.DayStyle.BorderColor = Color.Blue End Sub Protected Sub Command1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim currentDay As Integer = Calendar1.VisibleDate.Day Dim currentMonth As Integer = Calendar1.VisibleDate.Month Dim currentYear As Integer = Calendar1.VisibleDate.Year Calendar1.SelectedDates.Clear() ' Loop through current month and add all Wednesdays to the collection. Dim i As Integer For i = 1 To System.DateTime.DaysInMonth(currentYear, currentMonth) Dim targetDate As New DateTime(currentYear, currentMonth, i) If targetDate.DayOfWeek = DayOfWeek.Wednesday Then Calendar1.SelectedDates.Add(targetDate) End If Next i TextView1.Text = "Selection Count = " & Calendar1.SelectedDates.Count.ToString() End Sub </script> <html > <body> <mobile:form id="form1" runat="server"> <mobile:Calendar id="Calendar1" runat="server" OnSelectionChanged="ShowChanges" /> <mobile:TextView runat="server" id="TextView1" /> <mobile:Command ID="Command1" OnClick="Command1_Click" Runat="server">Select Weekdays</mobile:Command> </mobile:form> </body> </html>
<%@ Page Language="C#" Inherits="System.Web.UI.MobileControls.MobilePage" %> <%@ Import Namespace="System.Drawing" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { // Display the day header Calendar1.ShowDayHeader = true; // This allows the user to select a week or a month at a time. Calendar1.SelectionMode = CalendarSelectionMode.DayWeekMonth; // Set the BorderStyle and BorderColor properties. Calendar1.WebCalendar.DayStyle.BorderStyle = BorderStyle.Solid; Calendar1.WebCalendar.DayStyle.BorderColor = Color.Cyan; Calendar1.CalendarEntryText = "Your birthdate"; Calendar1.VisibleDate = DateTime.Parse("7/1/" + DateTime.Now.Year.ToString()); } protected void ShowChanges(Object sender, EventArgs e) { TextView1.Text = "The date you selected is " + Calendar1.SelectedDate.ToShortDateString(); // Distinguish the selected block using colors. Calendar1.WebCalendar.SelectedDayStyle.BackColor = Color.LightGreen; Calendar1.WebCalendar.SelectedDayStyle.BorderColor = Color.Gray; Calendar1.WebCalendar.DayStyle.BorderColor = Color.Blue; } protected void Command1_Click(object sender, EventArgs e) { int currentDay = Calendar1.VisibleDate.Day; int currentMonth = Calendar1.VisibleDate.Month; int currentYear = Calendar1.VisibleDate.Year; Calendar1.SelectedDates.Clear(); // Add all Wednesdays to the collection. for (int i = 1; i <= System.DateTime.DaysInMonth(currentYear , currentMonth); i++) { DateTime targetDate = new DateTime(currentYear, currentMonth, i); if (targetDate.DayOfWeek == DayOfWeek.Wednesday) Calendar1.SelectedDates.Add(targetDate); } TextView1.Text = "Selection Count =" + Calendar1.SelectedDates.Count.ToString(); } </script> <html > <body> <mobile:form id="form1" runat="server"> <mobile:Calendar id="Calendar1" runat="server" OnSelectionChanged="ShowChanges" /> <mobile:TextView runat="server" id="TextView1" /> <mobile:Command ID="Command1" OnClick="Command1_Click" Runat="server">Select Wednesdays</mobile:Command> </mobile:form> </body> </html>
.NET Framework のセキュリティ
継承階層
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照
構文<ControlValuePropertyAttribute("SelectedDate", GetType(DateTime), "1/1/0001")> _ Public Class Calendar Inherits WebControl Implements IPostBackEventHandler
[ControlValuePropertyAttribute("SelectedDate", typeof(DateTime), "1/1/0001")]
public class Calendar : WebControl, IPostBackEventHandler
[ControlValuePropertyAttribute(L"SelectedDate", typeof(DateTime), L"1/1/0001")] public ref class Calendar : public WebControl, IPostBackEventHandler
解説Calendar コントロールを使用して、Web ページに 1 つの月間カレンダーを表示します。このコントロールにより日付を選択し、前後の月に移動できます。Calendar コントロールは、System.Globalization 名前空間内のすべての System.Globalization.Calendar 型をサポートします。サポート対象には、グレゴリオ暦の他、回教暦などの年月の周期が異なる暦も含まれています。
SelectionMode プロパティを設定することにより、Calendar コントロールで 1 つの日付、1 つの週、または 1 つの月を選択できます。
既定では、コントロールはその月の日付、曜日、月名が付いたタイトルを表示し、月のそれぞれの日付に移動するリンク、および前後の月に移動するリンクを用意します。Calendar コントロールの異なった部分を制御するプロパティを設定することにより、このコントロールの外観をカスタマイズできます。コントロールの異なった部分のスタイルを指定するプロパティの一覧表を次に示します。
| DayHeaderStyle | |
| DayStyle | |
| NextPrevStyle | |
| OtherMonthDayStyle | |
| SelectedDayStyle | |
| SelectorStyle | |
| TitleStyle | |
| TodayDayStyle | |
| WeekendDayStyle |
コントロールのさまざまな部分を表示または非表示にすることもできます。表示または非表示にする部分を制御するプロパティの一覧を次の表に示します。
| ShowDayHeader | |
| ShowGridLines | |
| ShowNextPrevMonth | |
Calendar コントロールについてはデータ ソースへの連結はサポートされていませんが、それぞれの日付セルの内容と書式は変更できます。Calendar コントロールは、Web ページに表示される前に、構成要素であるコンポーネントを作成してアセンブルします。DayRender イベントは、Calendar コントロールの各日付セルが作成されるときに発生します。DayRender イベントのイベント ハンドラにコードを記述して、作成時に日付セルの内容と書式を制御できます。日付セルの内容をカスタマイズする方法の詳細については、OnDayRender のトピックを参照してください。
メモ |
|---|
| Calendar コントロールは、クライアントのブラウザに ECMAScript (JScript、JavaScript) を表示します。このコントロールが正常に機能するためには、クライアントのブラウザで ECMAScript が有効になっている必要があります。クライアント スクリプトの詳細については、「ASP.NET Web ページのクライアント スクリプト」を参照してください。 |
このコントロールに既定でレンダリングされるマークアップは、Web Content Accessibility Guidelines (WCAG) 1.0 の優先度 1 ガイドラインなどのユーザー補助に関する標準に適合しない可能性があります。このコントロールのユーザー補助サポートの詳細については、「ASP.NET コントロールとユーザー補助」を参照してください。
| Topic | Location |
|---|---|
| チュートリアル : Visual Web Developer での ASP.NET マスタ ページの作成と使用 | Visual Studio での ASP .NET Web アプリケーションの作成 |
| チュートリアル : Visual Web Developer での基本的な Web ページの作成 | Visual Studio での ASP .NET Web アプリケーションの作成 |
| チュートリアル : カスタム ビジネス オブジェクトへのデータ バインディング | Visual Studio での ASP .NET Web アプリケーションの作成 |
| チュートリアル : テーマを使用した Web サイトのカスタマイズ | Visual Studio での ASP .NET Web アプリケーションの作成 |
| 方法 : Calendar Web サーバー コントロールで選択された日付を読み取る | ASP .NET Web アプリケーションの作成 |
| 方法 : Calendar Web サーバー コントロールにおけるユーザーの日付選択を制御する | ASP .NET Web アプリケーションの作成 |
| 方法 : Calendar Web サーバー コントロールにおける日付選択に応答する | ASP .NET Web アプリケーションの作成 |
| 方法 : Calendar Web サーバー コントロールにおける日単位のカスタマイズ | ASP .NET Web アプリケーションの作成 |
| 方法 : Calendar Web サーバー コントロールにおける表示月の移動を制御する | ASP .NET Web アプリケーションの作成 |
| 方法 : Calendar Web サーバー コントロールに今日の日付をプログラムで設定する | ASP .NET Web アプリケーションの作成 |
| 方法 : Calendar Web サーバー コントロールの表示形式をカスタマイズする | ASP .NET Web アプリケーションの作成 |
| 方法 : スタイルを使用して、Calendar Web サーバー コントロール要素の表示形式を指定する | ASP .NET Web アプリケーションの作成 |
| 方法 : データベースで選択した日付を Calendar コントロールに表示する | ASP .NET Web アプリケーションの作成 |
使用例Web ページに Calendar コントロールを作成する方法を次のコード例に示します。
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> </head> <body> <form runat="server"> <asp:Calendar id="calendar1" runat="server"> <OtherMonthDayStyle ForeColor="LightGray"> </OtherMonthDayStyle> <TitleStyle BackColor="Blue" ForeColor="White"> </TitleStyle> <DayStyle BackColor="gray"> </DayStyle> <SelectedDayStyle BackColor="LightGray" Font-Bold="True"> </SelectedDayStyle> </asp:Calendar> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> </head> <body> <form runat="server"> <asp:Calendar id="calendar1" runat="server"> <OtherMonthDayStyle ForeColor="LightGray"> </OtherMonthDayStyle> <TitleStyle BackColor="Blue" ForeColor="White"> </TitleStyle> <DayStyle BackColor="gray"> </DayStyle> <SelectedDayStyle BackColor="LightGray" Font-Bold="True"> </SelectedDayStyle> </asp:Calendar> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> </head> <body> <form runat="server"> <asp:Calendar id="calendar1" runat="server"> <OtherMonthDayStyle ForeColor="LightGray"> </OtherMonthDayStyle> <TitleStyle BackColor="Blue" ForeColor="White"> </TitleStyle> <DayStyle BackColor="gray"> </DayStyle> <SelectedDayStyle BackColor="LightGray" Font-Bold="True"> </SelectedDayStyle> </asp:Calendar> </form> </body> </html>
継承階層
スレッド セーフ
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照
構文
使用例Imports System Imports System.Globalization Public Class SamplesCalendar Public Shared Sub Main() ' Sets a DateTime to April 3, 2002 of the Gregorian calendar. Dim myDT As New DateTime(2002, 4, 3, New GregorianCalendar()) ' Uses the default calendar of the InvariantCulture. Dim myCal As Calendar = CultureInfo.InvariantCulture.Calendar ' Displays the values of the DateTime. Console.WriteLine("April 3, 2002 of the Gregorian calendar:") DisplayValues(myCal, myDT) ' Adds 5 to every component of the DateTime. myDT = myCal.AddYears(myDT, 5) myDT = myCal.AddMonths(myDT, 5) myDT = myCal.AddWeeks(myDT, 5) myDT = myCal.AddDays(myDT, 5) myDT = myCal.AddHours(myDT, 5) myDT = myCal.AddMinutes(myDT, 5) myDT = myCal.AddSeconds(myDT, 5) myDT = myCal.AddMilliseconds(myDT, 5) ' Displays the values of the DateTime. Console.WriteLine("After adding 5 to each component of the DateTime:") DisplayValues(myCal, myDT) End Sub 'Main Public Shared Sub DisplayValues(myCal As Calendar, myDT As DateTime) Console.WriteLine(" Era: {0}", myCal.GetEra(myDT)) Console.WriteLine(" Year: {0}", myCal.GetYear(myDT)) Console.WriteLine(" Month: {0}", myCal.GetMonth(myDT)) Console.WriteLine(" DayOfYear: {0}", myCal.GetDayOfYear(myDT)) Console.WriteLine(" DayOfMonth: {0}", myCal.GetDayOfMonth(myDT)) Console.WriteLine(" DayOfWeek: {0}", myCal.GetDayOfWeek(myDT)) Console.WriteLine(" Hour: {0}", myCal.GetHour(myDT)) Console.WriteLine(" Minute: {0}", myCal.GetMinute(myDT)) Console.WriteLine(" Second: {0}", myCal.GetSecond(myDT)) Console.WriteLine(" Milliseconds: {0}", myCal.GetMilliseconds(myDT)) Console.WriteLine() End Sub 'DisplayValues End Class 'SamplesCalendar 'This code produces the following output. ' 'April 3, 2002 of the Gregorian calendar: ' Era: 1 ' Year: 2002 ' Month: 4 ' DayOfYear: 93 ' DayOfMonth: 3 ' DayOfWeek: Wednesday ' Hour: 0 ' Minute: 0 ' Second: 0 ' Milliseconds: 0 ' 'After adding 5 to each component of the DateTime: ' Era: 1 ' Year: 2007 ' Month: 10 ' DayOfYear: 286 ' DayOfMonth: 13 ' DayOfWeek: Saturday ' Hour: 5 ' Minute: 5 ' Second: 5 ' Milliseconds: 5
using System; using System.Globalization; public class SamplesCalendar { public static void Main() { // Sets a DateTime to April 3, 2002 of the Gregorian calendar. DateTime myDT = new DateTime( 2002, 4, 3, new GregorianCalendar() ); // Uses the default calendar of the InvariantCulture. Calendar myCal = CultureInfo.InvariantCulture.Calendar; // Displays the values of the DateTime. Console.WriteLine( "April 3, 2002 of the Gregorian calendar:" ); DisplayValues( myCal, myDT ); // Adds 5 to every component of the DateTime. myDT = myCal.AddYears( myDT, 5 ); myDT = myCal.AddMonths( myDT, 5 ); myDT = myCal.AddWeeks( myDT, 5 ); myDT = myCal.AddDays( myDT, 5 ); myDT = myCal.AddHours( myDT, 5 ); myDT = myCal.AddMinutes( myDT, 5 ); myDT = myCal.AddSeconds( myDT, 5 ); myDT = myCal.AddMilliseconds( myDT, 5 ); // Displays the values of the DateTime. Console.WriteLine( "After adding 5 to each component of the DateTime:" ); DisplayValues( myCal, myDT ); } public static void DisplayValues( Calendar myCal, DateTime myDT ) { Console.WriteLine( " Era: {0}", myCal.GetEra( myDT ) ); Console.WriteLine( " Year: {0}", myCal.GetYear( myDT ) ); Console.WriteLine( " Month: {0}", myCal.GetMonth( myDT ) ); Console.WriteLine( " DayOfYear: {0}", myCal.GetDayOfYear( myDT ) ); Console.WriteLine( " DayOfMonth: {0}", myCal.GetDayOfMonth( myDT ) ); Console.WriteLine( " DayOfWeek: {0}", myCal.GetDayOfWeek( myDT ) ); Console.WriteLine( " Hour: {0}", myCal.GetHour( myDT ) ); Console.WriteLine( " Minute: {0}", myCal.GetMinute( myDT ) ); Console.WriteLine( " Second: {0}", myCal.GetSecond( myDT ) ); Console.WriteLine( " Milliseconds: {0}", myCal.GetMilliseconds( myDT ) ); Console.WriteLine(); } } /* This code produces the following output. April 3, 2002 of the Gregorian calendar: Era: 1 Year: 2002 Month: 4 DayOfYear: 93 DayOfMonth: 3 DayOfWeek: Wednesday Hour: 0 Minute: 0 Second: 0 Milliseconds: 0 After adding 5 to each component of the DateTime: Era: 1 Year: 2007 Month: 10 DayOfYear: 286 DayOfMonth: 13 DayOfWeek: Saturday Hour: 5 Minute: 5 Second: 5 Milliseconds: 5 */
using namespace System; using namespace System::Globalization; void DisplayValues( Calendar^ myCal, DateTime myDT ) { Console::WriteLine( " Era: {0}", myCal->GetEra( myDT ) ); Console::WriteLine( " Year: {0}", myCal->GetYear( myDT ) ); Console::WriteLine( " Month: {0}", myCal->GetMonth( myDT ) ); Console::WriteLine( " DayOfYear: {0}", myCal->GetDayOfYear( myDT ) ); Console::WriteLine( " DayOfMonth: {0}", myCal->GetDayOfMonth( myDT ) ); Console::WriteLine( " DayOfWeek: {0}", myCal->GetDayOfWeek( myDT ) ); Console::WriteLine( " Hour: {0}", myCal->GetHour( myDT ) ); Console::WriteLine( " Minute: {0}", myCal->GetMinute( myDT ) ); Console::WriteLine( " Second: {0}", myCal->GetSecond( myDT ) ); Console::WriteLine( " Milliseconds: {0}", myCal->GetMilliseconds( myDT ) ); Console::WriteLine(); } int main() { // Sets a DateTime to April 3, 2002 of the Gregorian calendar. DateTime myDT = DateTime(2002,4,3,gcnew GregorianCalendar); // Uses the default calendar of the InvariantCulture. Calendar^ myCal = CultureInfo::InvariantCulture->Calendar; // Displays the values of the DateTime. Console::WriteLine( "April 3, 2002 of the Gregorian calendar:" ); DisplayValues( myCal, myDT ); // Adds 5 to every component of the DateTime. myDT = myCal->AddYears( myDT, 5 ); myDT = myCal->AddMonths( myDT, 5 ); myDT = myCal->AddWeeks( myDT, 5 ); myDT = myCal->AddDays( myDT, 5 ); myDT = myCal->AddHours( myDT, 5 ); myDT = myCal->AddMinutes( myDT, 5 ); myDT = myCal->AddSeconds( myDT, 5 ); myDT = myCal->AddMilliseconds( myDT, 5 ); // Displays the values of the DateTime. Console::WriteLine( "After adding 5 to each component of the DateTime:" ); DisplayValues( myCal, myDT ); } /* This code produces the following output. April 3, 2002 of the Gregorian calendar: Era: 1 Year: 2002 Month: 4 DayOfYear: 93 DayOfMonth: 3 DayOfWeek: Wednesday Hour: 0 Minute: 0 Second: 0 Milliseconds: 0 After adding 5 to each component of the DateTime: Era: 1 Year: 2007 Month: 10 DayOfYear: 286 DayOfMonth: 13 DayOfWeek: Saturday Hour: 5 Minute: 5 Second: 5 Milliseconds: 5 */
import System.* ; import System.Globalization.* ; public class SamplesCalendar { public static void main(String[] args) { // Sets a DateTime to April 3, 2002 of the Gregorian calendar. DateTime myDT = new DateTime(2002, 4, 3, new GregorianCalendar()); // Uses the default calendar of the InvariantCulture. Calendar myCal = CultureInfo.get_InvariantCulture().get_Calendar(); // Displays the values of the DateTime. Console.WriteLine("April 3, 2002 of the Gregorian calendar:"); DisplayValues(myCal, myDT); // Adds 5 to every component of the DateTime. myDT = myCal.AddYears(myDT, 5); myDT = myCal.AddMonths(myDT, 5); myDT = myCal.AddWeeks(myDT, 5); myDT = myCal.AddDays(myDT, 5); myDT = myCal.AddHours(myDT, 5); myDT = myCal.AddMinutes(myDT, 5); myDT = myCal.AddSeconds(myDT, 5); myDT = myCal.AddMilliseconds(myDT, 5); // Displays the values of the DateTime. Console.WriteLine("After adding 5 to each component of the DateTime:"); DisplayValues(myCal, myDT); } //main public static void DisplayValues(Calendar myCal, DateTime myDT) { Console.WriteLine(" Era: {0}", System.Convert.ToString(myCal.GetEra(myDT))); Console.WriteLine(" Year: {0}", System.Convert.ToString(myCal.GetYear(myDT))); Console.WriteLine(" Month: {0}", System.Convert.ToString(myCal.GetMonth(myDT))); Console.WriteLine(" DayOfYear: {0}", System.Convert.ToString(myCal.GetDayOfYear(myDT))); Console.WriteLine(" DayOfMonth: {0}", System.Convert.ToString(myCal.GetDayOfMonth(myDT))); Console.WriteLine(" DayOfWeek: {0}", System.Convert.ToString(myCal.GetDayOfWeek(myDT))); Console.WriteLine(" Hour: {0}", System.Convert.ToString(myCal.GetHour(myDT))); Console.WriteLine(" Minute: {0}", System.Convert.ToString(myCal.GetMinute(myDT))); Console.WriteLine(" Second: {0}", System.Convert.ToString(myCal.GetSecond(myDT))); Console.WriteLine(" Milliseconds: {0}", System.Convert.ToString(myCal.GetMilliseconds(myDT))); Console.WriteLine(); } //DisplayValues } //SamplesCalendar /* This code produces the following output. April 3, 2002 of the Gregorian calendar: Era: 1 Year: 2002 Month: 4 DayOfYear: 93 DayOfMonth: 3 DayOfWeek: Wednesday Hour: 0 Minute: 0 Second: 0 Milliseconds: 0 After adding 5 to each component of the DateTime: Era: 1 Year: 2007 Month: 10 DayOfYear: 286 DayOfMonth: 13 DayOfWeek: Saturday Hour: 5 Minute: 5 Second: 5 Milliseconds: 5 */
プラットフォームWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照
構文
プラットフォームWindows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照
構文
解説
使用例Calendar クラスの新しいインスタンスを作成および初期化する方法を次のコード例に示します。
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) ' Create new Calendar control. Dim calendar1 as Calendar = New Calendar ' Set Calendar properties. calendar1.OtherMonthDayStyle.ForeColor=System.Drawing.Color.LightGray calendar1.TitleStyle.BackColor=System.Drawing.Color.Blue calendar1.TitleStyle.ForeColor=System.Drawing.Color.White calendar1.DayStyle.BackColor=System.Drawing.Color.Gray calendar1.SelectionMode=CalendarSelectionMode.DayWeekMonth calendar1.ShowNextPrevMonth=true ' Add Calendar control to Controls collection. Form1.Controls.Add(calendar1) End Sub 'Page_Load </script> </head> <body> <form id="Form1" runat="server"> <h3>Calendar Example</h3> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // Create new Calendar control. Calendar calendar1 = new Calendar(); // Set Calendar properties. calendar1.OtherMonthDayStyle.ForeColor=System.Drawing.Color.LightGray; calendar1.TitleStyle.BackColor=System.Drawing.Color.Blue; calendar1.TitleStyle.ForeColor=System.Drawing.Color.White; calendar1.DayStyle.BackColor=System.Drawing.Color.Gray; calendar1.SelectionMode=CalendarSelectionMode.DayWeekMonth; calendar1.ShowNextPrevMonth=true; // Add Calendar control to Controls collection. Form1.Controls.Add(calendar1); } </script> </head> <body> <form id="Form1" runat="server"> <h3>Calendar Example</h3> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script runat="server"> function Page_Load(sender : Object, e : EventArgs) { // Create new Calendar control. var calendar1 : Calendar = new Calendar(); // Set Calendar properties. calendar1.OtherMonthDayStyle.ForeColor=System.Drawing.Color.LightGray; calendar1.TitleStyle.BackColor=System.Drawing.Color.Blue; calendar1.TitleStyle.ForeColor=System.Drawing.Color.White; calendar1.DayStyle.BackColor=System.Drawing.Color.Gray; calendar1.SelectionMode=CalendarSelectionMode.DayWeekMonth; calendar1.ShowNextPrevMonth=true; // Add Calendar control to Controls collection. Form1.Controls.Add(calendar1); } </script> </head> <body> <form id="Form1" runat="server"> <h3>Calendar Example</h3> </form> </body> </html>
プラットフォームWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照
パブリック フィールド
参照
パブリック プロパティ
参照
パブリック プロパティ
プロテクト プロパティ
参照
パブリック プロパティ
プロテクト プロパティ
参照
パブリック メソッド
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
参照
パブリック メソッド
プロテクト メソッド
明示的インターフェイスの実装| 名前 | 説明 | |
|---|---|---|
| System.Web.UI.IPostBackEventHandler.RaisePostBackEvent | このメンバの説明については、「IPostBackEventHandler.RaisePostBackEvent」を参照してください。 |
参照
パブリック メソッド
プロテクト メソッド
明示的インターフェイスの実装
参照Calendar データ型で公開されるメンバを以下の表に示します。
プロテクト コンストラクタ
パブリック フィールド
パブリック プロパティ
パブリック メソッド
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照Calendar データ型で公開されるメンバを以下の表に示します。
パブリック コンストラクタ
パブリック プロパティ
プロテクト プロパティ
パブリック メソッド
プロテクト メソッド
パブリック イベント| 名前 | 説明 | |
|---|---|---|
| DataBinding | サーバー コントロールがデータ ソースに連結すると発生します。(Control から継承されます。) |
| Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。(Control から継承されます。) |
| Init | サーバー コントロールが初期化されると発生します。これは、サーバー コントロールの有効期間における最初の手順です。(Control から継承されます。) |
| Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。(Control から継承されます。) |
| PreRender | Control オブジェクトの読み込み後、表示を開始する前に発生します。(Control から継承されます。) |
| SelectionChanged | Calendar コントロール内でユーザーが日、週、または月を選択するたびに発生します。 |
| Unload | サーバー コントロールがメモリからアンロードされると発生します。(Control から継承されます。) |
明示的インターフェイスの実装| 名前 | 説明 | |
|---|---|---|
| System.Web.UI.IPostBackEventHandler.RaisePostBackEvent | このメンバの説明については、「IPostBackEventHandler.RaisePostBackEvent」を参照してください。 |
参照1 つの月の月間カレンダーを表示します。ユーザーはこのカレンダーの日付を選択し、前後の月に移動できます。
Calendar データ型で公開されるメンバを以下の表に示します。
パブリック コンストラクタ
パブリック プロパティ
プロテクト プロパティ
パブリック メソッド
プロテクト メソッド
パブリック イベント| 名前 | 説明 | |
|---|---|---|
| DataBinding | サーバー コントロールがデータ ソースに連結すると発生します。(Control から継承されます。) |
| DayRender | 各日付が Calendar コントロールのコントロール階層で作成されると発生します。 |
| Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。(Control から継承されます。) |
| Init | サーバー コントロールが初期化されると発生します。これは、サーバー コントロールの有効期間における最初の手順です。(Control から継承されます。) |
| Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。(Control から継承されます。) |
| PreRender | Control オブジェクトの読み込み後、表示を開始する前に発生します。(Control から継承されます。) |
| SelectionChanged | ユーザーが日付セレクタ コントロールをクリックして 1 つの日付、1 つの週、または 1 つの月を選択したときに発生します。 |
| Unload | サーバー コントロールがメモリからアンロードされると発生します。(Control から継承されます。) |
| VisibleMonthChanged | ユーザーがタイトル見出しの前後の月へのナビゲーション コントロールをクリックしたときに発生します。 |
明示的インターフェイスの実装
参照