Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-select-a-range-of-dates-in-the-windows-forms-monthcalendar-control.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

3.0 KiB
Raw Blame History

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
Select a Range of Dates in MonthCalendar Control 03/30/2017
csharp
vb
cpp
dates [Windows Forms], selecting range in calendar controls
examples [Windows Forms], calendar controls
calendars [Windows Forms], selecting date range
MonthCalendar control [Windows Forms], selecting date range
95d9ab95-b0f8-4c19-9f63-b5cd4593a5d0

How to: Select a Range of Dates in the Windows Forms MonthCalendar Control

An important feature of the Windows Forms xref:System.Windows.Forms.MonthCalendar control is that the user can select a range of dates. This feature is an improvement over the date-selection feature of the xref:System.Windows.Forms.DateTimePicker control, which only enables the user to select a single date/time value. You can set a range of dates or get a selection range set by the user by using properties of the xref:System.Windows.Forms.MonthCalendar control. The following code example demonstrates how to set a selection range.

To select a range of dates

  1. Create xref:System.DateTime objects that represent the first and last dates in a range.

    Dim projectStart As Date = New DateTime(2001, 2, 13)  
    Dim projectEnd As Date = New DateTime(2001, 2, 28)  
    
    DateTime projectStart = new DateTime(2001, 2, 13);  
    DateTime projectEnd = new DateTime(2001, 2, 28);  
    
    DateTime projectStart = DateTime(2001, 2, 13);  
    DateTime projectEnd = DateTime(2001, 2, 28);  
    
  2. Set the xref:System.Windows.Forms.MonthCalendar.SelectionRange%2A property.

    MonthCalendar1.SelectionRange = New SelectionRange(projectStart, projectEnd)  
    
    monthCalendar1.SelectionRange = new SelectionRange(projectStart, projectEnd);  
    
    monthCalendar1->SelectionRange = gcnew  
       SelectionRange(projectStart, projectEnd);  
    

    or

    Set the xref:System.Windows.Forms.MonthCalendar.SelectionStart%2A and xref:System.Windows.Forms.MonthCalendar.SelectionEnd%2A properties.

    MonthCalendar1.SelectionStart = projectStart  
    MonthCalendar1.SelectionEnd = projectEnd  
    
    monthCalendar1.SelectionStart = projectStart;  
    monthCalendar1.SelectionEnd = projectEnd;  
    
    monthCalendar1->SelectionStart = projectStart;  
    monthCalendar1->SelectionEnd = projectEnd;  
    

See also