MonthCalendar
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| Exam 70-526 Preparation Guide: Add and configure date-setting controls on a Windows Form |
Contents |
The MonthCalendar control presents an intuitive graphical interface for users to view and set date information.
Inheritance hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.MonthCalendar
Useful properties
-
AnnuallyBoldedDates- Determines the array of DateTime objects that determines which annual days are displayed in bold.
-
-
BoldedDates- Contains the array ofDateTimeobjects that determines which nonrecurring dates are displayed in bold.
-
-
CalendarDimensions- Determines the number of columns and rows of months displayed. You can have multiple months displayed horizontally and vertically.
-
-
FirstDayOfWeek- Determines the first day of the week as displayed in the month calendar. By default, Sunday is shown as the first day of the week.
-
-
MaxDate- Determines the maximum allowable date.
-
-
MaxSelectionCount- Determines the maximum number of days that can be selected in a month calendar control.
-
-
MinDate- Determines the minimum allowable date.
-
-
MonthlyBoldedDates- Contains the array ofDateTimeobjects that determine which monthly days to bold.
-
-
SelectionEnd- Determines the end date of the selected range of dates.
-
-
SelectionRange- Determines the selected range of dates for a month calendar control.
-
-
SelectionStart- Determines the start date of the selected range of dates.
-
-
ShowToday- Indicates whether the date represented by theTodayDateproperty is displayed at the bottom of the control.
-
-
ShowTodayCircle- Indicates whether today's date is identified with a circle or square.
-
-
ShowWeekNumbers- Indicates whether the month calendar control displays week numbers (1-52) to the left of each row of days.
-
-
SingleMonthSize- Gets the minimum size to display one month of the calendar.
-
-
TitleBackColor- Indicates the background color of the title area of the calendar.
-
-
TitleForeColor- Indicates the foreground color of the title area of the calendar.
-
-
TodayDate- Determines the value that is used byMonthCalendaras today's date.
-
-
TodayDateSet- Gets a value indicating whether theTodayDateproperty has been explicitly set.
-
-
TrailingForeColor- Indicates the color of days in months that are not fully displayed in the control.
-
Selecting multiple dates
The user selects a single date by clicking a date in the MonthCalendar. The user can select a continuous range of dates, by holding down the Shift key while clicking the starting date and the ending date. The range of dates selected cannot be a greater number of days than is indicated by the MaxSelectionCount property.
At run time, the selected dates can be retrieved by accessing the SelectionStart and SelectionEnd properties. These expose the Start and End properties of the SelectionRange property. The following example shows how to access the SelectionStart and SelectionEnd properties through the DateSelected event.
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e) { if (monthCalendar1.SelectionStart != monthCalendar1.SelectionEnd) { MessageBox.Show("You chose the dates " + monthCalendar1.SelectionStart.ToLongDateString() + " to " + monthCalendar1.SelectionEnd.ToLongDateString()); } }
Adding a MonthCalendar manually
You can add a MonthCalendar to a form at run time in the following manner:
private void AddMonthCalendar() { MonthCalendar monthCalendar1 = new MonthCalendar(); //Set location. monthCalendar1.Location = new Point(20, 20); // Add the MonthCalendar to the form. this.Controls.Add(monthCalendar1); }
MSDN references
|


