The MonthCalendar control (System.Windows.Forms.MonthCalendar) resembles a calendar and shows a month and all its dates. The MonthCalendar control allows you to choose a month and a date. To choose a month, click the left and right arrows to move the month to the next or previous month.
Clicking the month header, will show all the months of the current year. Clicking the header even further will show all the years of the current decade, and clicking it once more will show all the year of the current century. You can customize the MonthCalendar control using the different properties it offers.
|AnnualyBoldedDates||A collection of dates of every year that will be displayed as bold in the MonthCalendar control.|
|BoldedDates||A collection of non-recurring dates that will be displayed as bold.|
|CalendarDimensions||Specifies the number of rows and columns of months to display.|
|FirstDayOfWeek||Specifies what day the calendar will consider as the first day of the week.|
|MaxDate||Specifies the maximum allowable date.|
|MaxSelectionCount||Specifies the maximum dates that the user can simultaneously select.|
|MinDate||Specifies the minimum allowable date.|
|MonthlyBoldedDates||A collection of dates within a month that will be bolded monthly.|
|ScrollChange||The number of months to move when clicking the navigation arrows.|
|SelectionEnd||If the user selects a range of date, this property indicates the last date in the range of dates.|
|SelectionRange||If the user selects a range of date, this property contains all the dates within the range of dates.|
|SelectionStart||If the user selects a range of date, this property indicates the first date in the range of dates.|
|ShowToday||Specifies whether to show the date today at the bottom of the control.|
|ShowTodayCircle||If set to true, the date today in the control will be enclosed with a square or a circle.|
|ShowWeekNumbers||Specifies whether the week number will be shown at the left of each row of the control.|
|TodayDate||The date used by the MonthCalendar as today’s date.|
Figure 1 – System.Windows.Forms.MonthCalendar Control Properties
You can bold certain dates annually. For example, you can indicate to bold every 25th of December to indicate Christmas. We use the AnnuallyBoldedDates property which accepts a collection of dates. Simply go to the Properties Inspector, find the property and click the dropdown arrow. You will be presented with the DateTime Collection Editor.
Simply click the Add or Remove buttons to add or remove dates. Click an item and you can specify the date by using the Value property inside the Properties Window to the right. Clicking the drop down button shows a date time picker that you can use to choose a date. Alternatively, you can simply type the date inside the text box. The MonthlyBoldedDates property marks date monthly whereas the BoldedDates properties mark specific dates just once while not continuance it monthly or annually.
By default, you can select a maximum of 7 consecutive dates. You do this by holding the Shift key and selecting the first and last dates. You can change the value of MaxSelectionCount property. All the dates between the two selected dates will be selected. If the selected dates exceed the number specified by MaxSelectionCount property, then the number of selected dates will be equal to that property. You can use the SelectionStart, SelectionEnd, and SelectionRange properties to retrieve the dates from the selection. If there is only one date selected, then you can simply use the SelectionStart to retrieve that date.
By default, only one month is shown, that is, 1 column and 1 row. You can change this using the CalendarDimensions property. For example, below shows a 2 by 2 MonthCalendar control which shows 4 months at the same time.
You can handle the events DateSelected and DateChanged. The DateSelected event occurs when a date or a range of dates are selected. The DateChanged event occurs when the user changes the selected date or range of dates.