Calendar Control in c# Windows Application

Calendar Control in c# Windows Application,MonthCalendar control,System.Windows.Forms.MonthCalendar
Share it:
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.


Calendar Control in c# Windows Application



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.


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 drop-down 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 while the BoldedDates properties mark specific dates only once without repeating 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 the MaxSelectionCount property. All the dates between the two selected dates will be selected. If the selected dates exceed the number specified by the 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 form 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.

MonthCalendar control



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.



Share it:

Windows Forms

Post A Comment:

0 comments: