DateRangeEventArgs Class

Provides data for the DateChanged or DateSelected events of the MonthCalendar control.

System::Object
  System::EventArgs
    System.Windows.Forms::DateRangeEventArgs

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public ref class DateRangeEventArgs : public EventArgs

The DateRangeEventArgs type exposes the following members.

  NameDescription
Public methodDateRangeEventArgsInitializes a new instance of the DateRangeEventArgs class.
Top

  NameDescription
Public propertyEndGets the last date/time value in the range that the user has selected.
Public propertyStartGets the first date/time value in the range that the user has selected.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The DateChanged event occurs when the currently selected date or range of dates changes; for example, when the user explicitly changes a selection within the current month or when the selection is implicitly changed in response to next/previous month navigation. The DateSelected event occurs when the user explicitly changes a selection. The DateRangeEventArgs constructor specifies the start and end for the new date range that has been selected.

NoteNote

If a single date is selected, the Start and End property values will be equal.

For more information about handling events, see Handling and Raising Events.

The following example displays a form containing a MonthCalendar control that displays one calendar year. The example demonstrates setting properties like BackColor, ForeColor, TitleBackColor, TitleForeColor, CalendarDimensions, and TrailingForeColor to customize the look of the calendar control. Other properties like AnnuallyBoldedDates, BoldedDates, and MonthlyBoldedDates are set to customize which dates are bolded. The example also sets properties to change the calendar format, including FirstDayOfWeek, MaxDate, MinDate, and MaxSelectionCount. The DateSelected and DateChanged events are also handled and their status displayed on the form.

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public System::Windows::Forms::Form
{
private:
   System::Windows::Forms::MonthCalendar^ monthCalendar1;
   System::Windows::Forms::TextBox^ textBox1;

public:
   Form1()
   {
      this->textBox1 = gcnew System::Windows::Forms::TextBox;
      this->textBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
      this->textBox1->Location = System::Drawing::Point( 48, 488 );
      this->textBox1->Multiline = true;
      this->textBox1->ReadOnly = true;
      this->textBox1->Size = System::Drawing::Size( 824, 32 );

      // Create the calendar. 
      this->monthCalendar1 = gcnew System::Windows::Forms::MonthCalendar;

      // Set the calendar location. 
      this->monthCalendar1->Location = System::Drawing::Point( 47, 16 );

      // Change the color. 
      this->monthCalendar1->BackColor = System::Drawing::SystemColors::Info;
      this->monthCalendar1->ForeColor = System::Drawing::Color::FromArgb( ((System::Byte)(192)) ),((System::Byte)(0)),((System::Byte)(192));
      this->monthCalendar1->TitleBackColor = System::Drawing::Color::Purple;
      this->monthCalendar1->TitleForeColor = System::Drawing::Color::Yellow;
      this->monthCalendar1->TrailingForeColor = System::Drawing::Color::FromArgb( ((System::Byte)(192)) ),((System::Byte)(192)),((System::Byte)(0));

      // Add dates to the AnnuallyBoldedDates array. 
      array<System::DateTime>^ temp1 = {System::DateTime( 2002, 4, 20, 0, 0, 0, 0 ),System::DateTime( 2002, 4, 28, 0, 0, 0, 0 ),System::DateTime( 2002, 5, 5, 0, 0, 0, 0 ),System::DateTime( 2002, 7, 4, 0, 0, 0, 0 ),System::DateTime( 2002, 12, 15, 0, 0, 0, 0 ),System::DateTime( 2002, 12, 18, 0, 0, 0, 0 )};
      this->monthCalendar1->AnnuallyBoldedDates = temp1;

      // Add dates to BoldedDates array. 
      array<System::DateTime>^ temp2 = {System::DateTime( 2002, 9, 26, 0, 0, 0, 0 )};
      this->monthCalendar1->BoldedDates = temp2;

      // Add dates to MonthlyBoldedDates array. 
      array<System::DateTime>^ temp5 = {System::DateTime( 2002, 1, 15, 0, 0, 0, 0 ),System::DateTime( 2002, 1, 30, 0, 0, 0, 0 )};
      this->monthCalendar1->MonthlyBoldedDates = temp5;

      // Configure the calendar to display 3 rows by 4 columns of months. 
      this->monthCalendar1->CalendarDimensions = System::Drawing::Size( 4, 3 );

      // Set week to begin on Monday. 
      this->monthCalendar1->FirstDayOfWeek = System::Windows::Forms::Day::Monday;

      // Set the maximum visible date on the calendar to 12/31/2010. 
      this->monthCalendar1->MaxDate = System::DateTime( 2010, 12, 31, 0, 0, 0, 0 );

      // Set the minimum visible date on calendar to 12/31/2010. 
      this->monthCalendar1->MinDate = System::DateTime( 1999, 1, 1, 0, 0, 0, 0 );

      // Only allow 21 days to be selected at the same time. 
      this->monthCalendar1->MaxSelectionCount = 21;

      // Set the calendar to move one month at a time when navigating using the arrows. 
      this->monthCalendar1->ScrollChange = 1;

      // Do not show the S"Today" banner.
      this->monthCalendar1->ShowToday = false;

      // Do not circle today's date. 
      this->monthCalendar1->ShowTodayCircle = false;

      // Show the week numbers to the left of each week. 
      this->monthCalendar1->ShowWeekNumbers = true;

      // Add event handlers for the DateSelected and DateChanged events 
      this->monthCalendar1->DateSelected += gcnew System::Windows::Forms::DateRangeEventHandler( this, &Form1::monthCalendar1_DateSelected );
      this->monthCalendar1->DateChanged += gcnew System::Windows::Forms::DateRangeEventHandler( this, &Form1::monthCalendar1_DateChanged );

      // Set up how the form should be displayed and add the controls to the form. 
      this->ClientSize = System::Drawing::Size( 920, 566 );
      array<System::Windows::Forms::Control^>^temp0 = {this->textBox1,this->monthCalendar1};
      this->Controls->AddRange( temp0 );
      this->Text = "Month Calendar Example";
   }


private:
   void monthCalendar1_DateSelected( Object^ /*sender*/, System::Windows::Forms::DateRangeEventArgs^ e )
   {

      // Show the start and end dates in the text box. 
      this->textBox1->Text = String::Format( "Date Selected: Start = {0} : End = {1}", e->Start.ToShortDateString(), e->End.ToShortDateString() );
   }

   void monthCalendar1_DateChanged( Object^ /*sender*/, System::Windows::Forms::DateRangeEventArgs^ e )
   {

      // Show the start and end dates in the text box. 
      this->textBox1->Text = String::Format( "Date Changed: Start = {0} : End = {1}", e->Start.ToShortDateString(), e->End.ToShortDateString() );
   }

};


[STAThread]
int main()
{
   Application::Run( gcnew Form1 );
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft