Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Code: Selecting a Range of Dates in a Calendar Control (Visual C#)

Visual Studio .NET 2003

This example selects a range of dates in a Windows Forms MonthCalendar control. In this example, when the user selects a date the week is selected.


private void monthCalendar1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e)
    DateTime startDate = e.Start;
    startDate = startDate.AddDays(-(double)startDate.DayOfWeek);
    monthCalendar1.SelectionStart = startDate;
    monthCalendar1.SelectionEnd = startDate.AddDays(6);

Compiling the Code

This example requires:

  • A Windows Form with a MonthCalendar control named monthCalendar1. Set monthCalendar1's DateSelected event handler to monthCalendar1_DateSelected.

See Also

Windows Forms Example Topics | MonthCalendar Control (Windows Forms)

© 2015 Microsoft