MonthCalendar 클래스
사용자가 시각적 월별 달력 화면 표시로 날짜를 선택할 수 있게 하는 Windows 컨트롤을 나타냅니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class MonthCalendar
Inherits Control
‘사용 방법
Dim instance As MonthCalendar
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class MonthCalendar : Control
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
public ref class MonthCalendar : public Control
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
public class MonthCalendar extends Control
ComVisibleAttribute(true)
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
public class MonthCalendar extends Control
설명
MonthCalendar 컨트롤을 사용하면 화면에서 날짜를 선택할 수 있습니다. 또한 MinDate 및 MaxDate 속성을 설정하여 선택할 수 있는 날짜와 시간을 제한할 수 있습니다.
ForeColor, Font, TitleBackColor, TitleForeColor, TrailingForeColor 및 BackColor 속성을 설정하여 컨트롤의 달력 부분 모양을 변경할 수 있습니다.
MonthCalendar 컨트롤은 운영 체제에서 그리므로 Paint 이벤트가 발생하지 않습니다. MonthCalendar 컨트롤 모양을 사용자 지정해야 할 경우 OnPrint 메서드를 재정의하고, OnPrint의 기본 구현을 호출한 다음 사용자 지정 그리기를 수행해야 합니다.
날짜 형식을 사용자 지정하거나 날짜를 하나만 선택할 수 있도록 제한하려면 MonthCalendar 대신 DateTimePicker 컨트롤을 사용합니다. DateTimePicker를 사용하면 날짜/시간 값의 유효성을 확인할 필요가 없습니다.
MonthCalendar 컨트롤에 대한 자세한 내용은 https://www.microsoft.com/korea/msdn에 있는 Platform SDK 설명서의 "Month Calendar Controls"를 참조하십시오.
참고
비주얼 스타일이 설정된 MonthCalendar를 사용하면 MonthCalendar 컨트롤의 선택 범위가 올바르게 그려지지 않고 ShowTodayCircle이 true로 설정된 경우 오늘 날짜가 사각형 안에 포함됩니다.
예제
다음 코드 예제에서는 달력 년도 일년을 표시하는 MonthCalendar 컨트롤이 들어 있는 폼을 표시합니다. 예제에서는 BackColor, ForeColor, TitleBackColor, TitleForeColor, CalendarDimensions 및 TrailingForeColor 속성을 설정하여 달력 컨트롤의 모양을 사용자 지정하는 방법을 보여 줍니다. AnnuallyBoldedDates, BoldedDates, MonthlyBoldedDates 등의 다른 속성을 설정하여 굵게 표시되는 날짜를 사용자 지정할 수 있습니다. 또한 예제에서는 FirstDayOfWeek, MaxDate, MinDate 및 MaxSelectionCount 속성을 설정하여 달력 형식을 변경합니다. 또한 DateSelected 및 DateChanged 이벤트가 처리되며 그 상태가 폼에 표시됩니다.
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public NotInheritable Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents MonthCalendar1 As System.Windows.Forms.MonthCalendar
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.STAThread()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1)
End Sub 'Main
Public Sub New()
MyBase.New()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.TextBox1.Location = New System.Drawing.Point(48, 488)
Me.TextBox1.Multiline = True
Me.TextBox1.ReadOnly = True
Me.TextBox1.Size = New System.Drawing.Size(824, 32)
' Create the calendar.
Me.MonthCalendar1 = New System.Windows.Forms.MonthCalendar
' Set the calendar location.
Me.MonthCalendar1.Location = New System.Drawing.Point(47, 16)
' Change the color.
Me.MonthCalendar1.BackColor = System.Drawing.SystemColors.Info
Me.MonthCalendar1.ForeColor = System.Drawing.Color.FromArgb( _
CType(192, System.Byte), CType(0, System.Byte), CType(192, System.Byte))
Me.MonthCalendar1.TitleBackColor = System.Drawing.Color.Purple
Me.MonthCalendar1.TitleForeColor = System.Drawing.Color.Yellow
Me.MonthCalendar1.TrailingForeColor = System.Drawing.Color.FromArgb( _
CType(192, System.Byte), CType(192, System.Byte), CType(0, System.Byte))
' Add dates to the AnnuallyBoldedDates array.
Me.MonthCalendar1.AnnuallyBoldedDates = New System.DateTime() _
{New System.DateTime(2002, 4, 20, 0, 0, 0, 0), _
New System.DateTime(2002, 4, 28, 0, 0, 0, 0), _
New System.DateTime(2002, 5, 5, 0, 0, 0, 0), _
New System.DateTime(2002, 7, 4, 0, 0, 0, 0), _
New System.DateTime(2002, 12, 15, 0, 0, 0, 0), _
New System.DateTime(2002, 12, 18, 0, 0, 0, 0)}
' Add dates to BoldedDates array.
Me.MonthCalendar1.BoldedDates = New System.DateTime() {New System.DateTime(2002, 9, 26, 0, 0, 0, 0)}
' Add dates to MonthlyBoldedDates array.
Me.MonthCalendar1.MonthlyBoldedDates = New System.DateTime() _
{New System.DateTime(2002, 1, 15, 0, 0, 0, 0), _
New System.DateTime(2002, 1, 30, 0, 0, 0, 0)}
' Configure the calendar to display 3 rows by 4 columns of months.
Me.MonthCalendar1.CalendarDimensions = New System.Drawing.Size(4, 3)
' Set the week to begin on Monday.
Me.MonthCalendar1.FirstDayOfWeek = System.Windows.Forms.Day.Monday
' Sets the maximum visible date on the calendar to 12/31/2010.
Me.MonthCalendar1.MaxDate = New System.DateTime(2010, 12, 31, 0, 0, 0, 0)
' Set the minimum visible date on the calendar to 12/31/2010.
Me.MonthCalendar1.MinDate = New System.DateTime(1999, 1, 1, 0, 0, 0, 0)
' Only allow 21 days to be selected at the same time.
Me.MonthCalendar1.MaxSelectionCount = 21
' Set the calendar to move one month at a time when navigating using the arrows.
Me.MonthCalendar1.ScrollChange = 1
' Do not show the "Today" banner.
Me.MonthCalendar1.ShowToday = False
' Do not circle today's date.
Me.MonthCalendar1.ShowTodayCircle = False
' Show the week numbers to the left of each week.
Me.MonthCalendar1.ShowWeekNumbers = True
' Set up how the form should be displayed and add the controls to the form.
Me.ClientSize = New System.Drawing.Size(920, 566)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.MonthCalendar1})
Me.Text = "Month Calendar Example"
End Sub
Private Sub monthCalendar1_DateSelected(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
' Show the start and end dates in the text box.
Me.TextBox1.Text = "Date Selected: Start = " + _
e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString()
End Sub
Private Sub monthCalendar1_DateChanged(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
' Show the start and end dates in the text box.
Me.TextBox1.Text = "Date Changed: Start = " + _
e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString()
End Sub
End Class
using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.TextBox textBox1;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox1.Location = new System.Drawing.Point(48, 488);
this.textBox1.Multiline = true;
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(824, 32);
// Create the calendar.
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
// Set the calendar location.
this.monthCalendar1.Location = new System.Drawing.Point(47, 16);
// Change the color.
this.monthCalendar1.BackColor = System.Drawing.SystemColors.Info;
this.monthCalendar1.ForeColor = System.Drawing.Color.FromArgb(
((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(192)));
this.monthCalendar1.TitleBackColor = System.Drawing.Color.Purple;
this.monthCalendar1.TitleForeColor = System.Drawing.Color.Yellow;
this.monthCalendar1.TrailingForeColor = System.Drawing.Color.FromArgb(
((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(0)));
// Add dates to the AnnuallyBoldedDates array.
this.monthCalendar1.AnnuallyBoldedDates =
new System.DateTime[] { new System.DateTime(2002, 4, 20, 0, 0, 0, 0),
new System.DateTime(2002, 4, 28, 0, 0, 0, 0),
new System.DateTime(2002, 5, 5, 0, 0, 0, 0),
new System.DateTime(2002, 7, 4, 0, 0, 0, 0),
new System.DateTime(2002, 12, 15, 0, 0, 0, 0),
new System.DateTime(2002, 12, 18, 0, 0, 0, 0)};
// Add dates to BoldedDates array.
this.monthCalendar1.BoldedDates = new System.DateTime[] {new System.DateTime(2002, 9, 26, 0, 0, 0, 0)};
// Add dates to MonthlyBoldedDates array.
this.monthCalendar1.MonthlyBoldedDates =
new System.DateTime[] {new System.DateTime(2002, 1, 15, 0, 0, 0, 0),
new System.DateTime(2002, 1, 30, 0, 0, 0, 0)};
// Configure the calendar to display 3 rows by 4 columns of months.
this.monthCalendar1.CalendarDimensions = new System.Drawing.Size(4, 3);
// Set week to begin on Monday.
this.monthCalendar1.FirstDayOfWeek = System.Windows.Forms.Day.Monday;
// Set the maximum visible date on the calendar to 12/31/2010.
this.monthCalendar1.MaxDate = new System.DateTime(2010, 12, 31, 0, 0, 0, 0);
// Set the minimum visible date on calendar to 12/31/2010.
this.monthCalendar1.MinDate = new System.DateTime(1999, 1, 1, 0, 0, 0, 0);
// Only allow 21 days to be selected at the same time.
this.monthCalendar1.MaxSelectionCount = 21;
// Set the calendar to move one month at a time when navigating using the arrows.
this.monthCalendar1.ScrollChange = 1;
// Do not show the "Today" banner.
this.monthCalendar1.ShowToday = false;
// Do not circle today's date.
this.monthCalendar1.ShowTodayCircle = false;
// Show the week numbers to the left of each week.
this.monthCalendar1.ShowWeekNumbers = true;
// Add event handlers for the DateSelected and DateChanged events
this.monthCalendar1.DateSelected += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateSelected);
this.monthCalendar1.DateChanged += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateChanged);
// Set up how the form should be displayed and add the controls to the form.
this.ClientSize = new System.Drawing.Size(920, 566);
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.textBox1, this.monthCalendar1});
this.Text = "Month Calendar Example";
}
private void monthCalendar1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e)
{
// Show the start and end dates in the text box.
this.textBox1.Text = "Date Selected: Start = " +
e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString();
}
private void monthCalendar1_DateChanged(object sender, System.Windows.Forms.DateRangeEventArgs e)
{
// Show the start and end dates in the text box.
this.textBox1.Text = "Date Changed: Start = " +
e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString();
}
}
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public System::Windows::Forms::Form
{
private:
System::Windows::Forms::MonthCalendar^ monthCalendar1;
System::Windows::Forms::TextBox^ textBox1;
public:
Form1()
{
this->textBox1 = gcnew System::Windows::Forms::TextBox;
this->textBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
this->textBox1->Location = System::Drawing::Point( 48, 488 );
this->textBox1->Multiline = true;
this->textBox1->ReadOnly = true;
this->textBox1->Size = System::Drawing::Size( 824, 32 );
// Create the calendar.
this->monthCalendar1 = gcnew System::Windows::Forms::MonthCalendar;
// Set the calendar location.
this->monthCalendar1->Location = System::Drawing::Point( 47, 16 );
// Change the color.
this->monthCalendar1->BackColor = System::Drawing::SystemColors::Info;
this->monthCalendar1->ForeColor = System::Drawing::Color::FromArgb( ((System::Byte)(192)) ),((System::Byte)(0)),((System::Byte)(192));
this->monthCalendar1->TitleBackColor = System::Drawing::Color::Purple;
this->monthCalendar1->TitleForeColor = System::Drawing::Color::Yellow;
this->monthCalendar1->TrailingForeColor = System::Drawing::Color::FromArgb( ((System::Byte)(192)) ),((System::Byte)(192)),((System::Byte)(0));
// Add dates to the AnnuallyBoldedDates array.
array<System::DateTime>^ temp1 = {System::DateTime( 2002, 4, 20, 0, 0, 0, 0 ),System::DateTime( 2002, 4, 28, 0, 0, 0, 0 ),System::DateTime( 2002, 5, 5, 0, 0, 0, 0 ),System::DateTime( 2002, 7, 4, 0, 0, 0, 0 ),System::DateTime( 2002, 12, 15, 0, 0, 0, 0 ),System::DateTime( 2002, 12, 18, 0, 0, 0, 0 )};
this->monthCalendar1->AnnuallyBoldedDates = temp1;
// Add dates to BoldedDates array.
array<System::DateTime>^ temp2 = {System::DateTime( 2002, 9, 26, 0, 0, 0, 0 )};
this->monthCalendar1->BoldedDates = temp2;
// Add dates to MonthlyBoldedDates array.
array<System::DateTime>^ temp5 = {System::DateTime( 2002, 1, 15, 0, 0, 0, 0 ),System::DateTime( 2002, 1, 30, 0, 0, 0, 0 )};
this->monthCalendar1->MonthlyBoldedDates = temp5;
// Configure the calendar to display 3 rows by 4 columns of months.
this->monthCalendar1->CalendarDimensions = System::Drawing::Size( 4, 3 );
// Set week to begin on Monday.
this->monthCalendar1->FirstDayOfWeek = System::Windows::Forms::Day::Monday;
// Set the maximum visible date on the calendar to 12/31/2010.
this->monthCalendar1->MaxDate = System::DateTime( 2010, 12, 31, 0, 0, 0, 0 );
// Set the minimum visible date on calendar to 12/31/2010.
this->monthCalendar1->MinDate = System::DateTime( 1999, 1, 1, 0, 0, 0, 0 );
// Only allow 21 days to be selected at the same time.
this->monthCalendar1->MaxSelectionCount = 21;
// Set the calendar to move one month at a time when navigating using the arrows.
this->monthCalendar1->ScrollChange = 1;
// Do not show the S"Today" banner.
this->monthCalendar1->ShowToday = false;
// Do not circle today's date.
this->monthCalendar1->ShowTodayCircle = false;
// Show the week numbers to the left of each week.
this->monthCalendar1->ShowWeekNumbers = true;
// Add event handlers for the DateSelected and DateChanged events
this->monthCalendar1->DateSelected += gcnew System::Windows::Forms::DateRangeEventHandler( this, &Form1::monthCalendar1_DateSelected );
this->monthCalendar1->DateChanged += gcnew System::Windows::Forms::DateRangeEventHandler( this, &Form1::monthCalendar1_DateChanged );
// Set up how the form should be displayed and add the controls to the form.
this->ClientSize = System::Drawing::Size( 920, 566 );
array<System::Windows::Forms::Control^>^temp0 = {this->textBox1,this->monthCalendar1};
this->Controls->AddRange( temp0 );
this->Text = "Month Calendar Example";
}
private:
void monthCalendar1_DateSelected( Object^ /*sender*/, System::Windows::Forms::DateRangeEventArgs^ e )
{
// Show the start and end dates in the text box.
this->textBox1->Text = String::Format( "Date Selected: Start = {0} : End = {1}", e->Start.ToShortDateString(), e->End.ToShortDateString() );
}
void monthCalendar1_DateChanged( Object^ /*sender*/, System::Windows::Forms::DateRangeEventArgs^ e )
{
// Show the start and end dates in the text box.
this->textBox1->Text = String::Format( "Date Changed: Start = {0} : End = {1}", e->Start.ToShortDateString(), e->End.ToShortDateString() );
}
};
[STAThread]
int main()
{
Application::Run( gcnew Form1 );
}
import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;
public class Form1 extends System.Windows.Forms.Form
{
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.TextBox textBox1;
/** @attribute STAThread()
*/
public static void main(String[] args)
{
Application.Run(new Form1());
} //main
public Form1()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1.set_BorderStyle(
System.Windows.Forms.BorderStyle.FixedSingle);
this.textBox1.set_Location(new System.Drawing.Point(48, 488));
this.textBox1.set_Multiline(true);
this.textBox1.set_ReadOnly(true);
this.textBox1.set_Size(new System.Drawing.Size(824, 32));
// Create the calendar.
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
// Set the calendar location.
this.monthCalendar1.set_Location(new System.Drawing.Point(47, 16));
// Change the color.
this.monthCalendar1.set_BackColor(
System.Drawing.SystemColors.get_Info());
this.monthCalendar1.set_ForeColor(
System.Drawing.Color.FromArgb(192, 0, 192));
this.monthCalendar1.set_TitleBackColor(System.Drawing.Color.get_Purple());
this.monthCalendar1.set_TitleForeColor(System.Drawing.Color.get_Yellow());
this.monthCalendar1.set_TrailingForeColor(
System.Drawing.Color.FromArgb(192, 192, 0));
// Add dates to the AnnuallyBoldedDates array.
this.monthCalendar1.set_AnnuallyBoldedDates(new System.DateTime[] {
new System.DateTime(2002, 4, 20, 0, 0, 0, 0),
new System.DateTime(2002, 4, 28, 0, 0, 0, 0),
new System.DateTime(2002, 5, 5, 0, 0, 0, 0),
new System.DateTime(2002, 7, 4, 0, 0, 0, 0),
new System.DateTime(2002, 12, 15, 0, 0, 0, 0),
new System.DateTime(2002, 12, 18, 0, 0, 0, 0) });
// Add dates to BoldedDates array.
this.monthCalendar1.set_BoldedDates(new System.DateTime[] {
new System.DateTime(2002, 9, 26, 0, 0, 0, 0) });
// Add dates to MonthlyBoldedDates array.
this.monthCalendar1.set_MonthlyBoldedDates(new System.DateTime[] {
new System.DateTime(2002, 1, 15, 0, 0, 0, 0),
new System.DateTime(2002, 1, 30, 0, 0, 0, 0) });
// Configure the calendar to display 3 rows by 4 columns of months.
this.monthCalendar1.set_CalendarDimensions(new System.Drawing.Size(4, 3));
// Set week to begin on Monday.
this.monthCalendar1.set_FirstDayOfWeek(System.Windows.Forms.Day.Monday);
// Set the maximum visible date on the calendar to 12/31/2010.
this.monthCalendar1.set_MaxDate(
new System.DateTime(2010, 12, 31, 0, 0, 0, 0));
// Set the minimum visible date on calendar to 12/31/2010.
this.monthCalendar1.set_MinDate(
new System.DateTime(1999, 1, 1, 0, 0, 0, 0));
// Only allow 21 days to be selected at the same time.
this.monthCalendar1.set_MaxSelectionCount(21);
// Set the calendar to move one month at a time when navigating
// using the arrows.
this.monthCalendar1.set_ScrollChange(1);
// Do not show the "Today" banner.
this.monthCalendar1.set_ShowToday(false);
// Do not circle today's date.
this.monthCalendar1.set_ShowTodayCircle(false);
// Show the week numbers to the left of each week.
this.monthCalendar1.set_ShowWeekNumbers(true);
// Add event handlers for the DateSelected and DateChanged events
this.monthCalendar1.add_DateSelected(
new System.Windows.Forms.DateRangeEventHandler(
this.monthCalendar1_DateSelected));
this.monthCalendar1.add_DateChanged(
new System.Windows.Forms.DateRangeEventHandler(
this.monthCalendar1_DateChanged));
// Set up how the form should be displayed and add the controls to
// the form.
this.set_ClientSize(new System.Drawing.Size(920, 566));
this.get_Controls().AddRange(new System.Windows.Forms.Control[] {
this.textBox1, this.monthCalendar1 });
this.set_Text("Month Calendar Example");
} //Form1
private void monthCalendar1_DateSelected(Object sender,
System.Windows.Forms.DateRangeEventArgs e)
{
// Show the start and end dates in the text box.
this.textBox1.set_Text("Date Selected: Start = "
+ e.get_Start().ToShortDateString() + " : End = "
+ e.get_End().ToShortDateString());
} //monthCalendar1_DateSelected
private void monthCalendar1_DateChanged(Object sender,
System.Windows.Forms.DateRangeEventArgs e)
{
// Show the start and end dates in the text box.
this.textBox1.set_Text("Date Changed: Start = "
+ e.get_Start().ToShortDateString() + " : End = "
+ e.get_End().ToShortDateString());
} //monthCalendar1_DateChanged
} //Form1
상속 계층 구조
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.MonthCalendar
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
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에서 지원