This documentation is archived and is not being maintained.

MonthCalendar Class

Represents a Windows control that enables the user to select a date using a visual monthly calendar display.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<DefaultBindingPropertyAttribute("SelectionRange")> _
Public Class MonthCalendar _
	Inherits Control
Dim instance As MonthCalendar

The MonthCalendar control allows the user to select a date using a visual display. You can limit the date and times that can be selected by setting the MinDate and MaxDate properties.

You can change the look of the calendar portion of the control by setting the ForeColor, Font, TitleBackColor, TitleForeColor, TrailingForeColor, and BackColor properties.


The DateTimePicker control only supports Gregorian calendars.

The MonthCalendar control is drawn by the operating system, so the Paint event is never raised. If you need to provide a customized look to the MonthCalendar control, you should override the OnPrint method, call the base implementation of OnPrint, and then perform custom painting.

If you need custom date formatting and a selection limited to just one date, you might consider using a DateTimePicker control instead of a MonthCalendar. Using the DateTimePicker eliminates much of the need for validating date/time values.

For more information on month calendar controls, see Month Calendar Control Reference.

The following code example displays a form containing a MonthCalendar control that displays one calendar year. The example demonstrates setting the BackColor, ForeColor, TitleBackColor, TitleForeColor, CalendarDimensions, and TrailingForeColor properties to customize the look of the calendar control. Other properties such as AnnuallyBoldedDates, BoldedDates, and MonthlyBoldedDates are set to customize which dates are bold. The example also sets the FirstDayOfWeek, MaxDate, MinDate, and MaxSelectionCount properties to change the calendar format. The DateSelected and DateChanged events are also handled and their status is displayed on the form.

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()

        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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Pocket PC

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0