SelectionRange Konstruktorer

Definition

Initierar en ny instans av SelectionRange klassen.

Överlagringar

Name Description
SelectionRange()

Initierar en ny instans av SelectionRange klassen.

SelectionRange(SelectionRange)

Initierar en ny instans av SelectionRange klassen med det angivna markeringsintervallet.

SelectionRange(DateTime, DateTime)

Initierar en ny instans av SelectionRange klassen med angivna start- och slutdatum.

SelectionRange()

Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs

Initierar en ny instans av SelectionRange klassen.

public:
 SelectionRange();
public SelectionRange();
Public Sub New ()

Exempel

I följande exempel skapas ett SelectionRange objekt, dess Start egenskaper och End egenskaper anges och objektet SelectionRange tilldelas SelectionRange till kontrollens MonthCalendar egenskap. När händelsen DateChanged utlöses Start visas egenskapsvärdena och End i textrutorna. Det här exemplet förutsätter att du har en Form med två TextBox kontroller, en Buttonoch en MonthCalendar kontroll.

private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Create a SelectionRange object and set its Start and End properties.
      SelectionRange^ sr = gcnew SelectionRange;
      sr->Start = DateTime::Parse( this->textBox1->Text );
      sr->End = DateTime::Parse( this->textBox2->Text );
      
      /* Assign the SelectionRange object to the
            SelectionRange property of the MonthCalendar control. */
      this->monthCalendar1->SelectionRange = sr;
   }

   void monthCalendar1_DateChanged( Object^ /*sender*/, DateRangeEventArgs^ /*e*/ )
   {
      /* Display the Start and End property values of
            the SelectionRange object in the text boxes. */
      this->textBox1->Text = monthCalendar1->SelectionRange->Start.Date.ToShortDateString();
      this->textBox2->Text = monthCalendar1->SelectionRange->End.Date.ToShortDateString();
   }
private void button1_Click(object sender, System.EventArgs e)
{
   // Create a SelectionRange object and set its Start and End properties.
   SelectionRange sr = new SelectionRange();
   sr.Start = DateTime.Parse(this.textBox1.Text);
   sr.End = DateTime.Parse(this.textBox2.Text);
   /* Assign the SelectionRange object to the 
      SelectionRange property of the MonthCalendar control. */
   this.monthCalendar1.SelectionRange = sr;
}

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
   /* Display the Start and End property values of 
      the SelectionRange object in the text boxes. */
   this.textBox1.Text = 
     monthCalendar1.SelectionRange.Start.Date.ToShortDateString();
   this.textBox2.Text = 
     monthCalendar1.SelectionRange.End.Date.ToShortDateString();
}
Private Sub button1_Click(sender As Object, _
  e As EventArgs) Handles button1.Click
   ' Create a SelectionRange object and set its Start and End properties.
   Dim sr As New SelectionRange()
   sr.Start = DateTime.Parse(Me.textBox1.Text)
   sr.End = DateTime.Parse(Me.textBox2.Text)
   ' Assign the SelectionRange object to the
   ' SelectionRange property of the MonthCalendar control. 
   Me.monthCalendar1.SelectionRange = sr
End Sub 


Private Sub monthCalendar1_DateChanged(sender As Object, _
  e As DateRangeEventArgs) Handles monthCalendar1.DateChanged
   ' Display the Start and End property values of
   ' the SelectionRange object in the text boxes. 
   Me.textBox1.Text = monthCalendar1.SelectionRange.Start.Date.ToShortDateString()
   Me.textBox2.Text = monthCalendar1.SelectionRange.End.Date.ToShortDateString()
End Sub

Kommentarer

Värdena Start och End anges till null när konstruktorn används.

Gäller för

SelectionRange(SelectionRange)

Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs

Initierar en ny instans av SelectionRange klassen med det angivna markeringsintervallet.

public:
 SelectionRange(System::Windows::Forms::SelectionRange ^ range);
public SelectionRange(System.Windows.Forms.SelectionRange range);
new System.Windows.Forms.SelectionRange : System.Windows.Forms.SelectionRange -> System.Windows.Forms.SelectionRange
Public Sub New (range As SelectionRange)

Parametrar

range
SelectionRange

Den befintliga SelectionRange.

Exempel

I följande exempel skapas ett SelectionRange objekt, dess Start egenskaper och End egenskaper anges och objektet SelectionRange tilldelas SelectionRange till kontrollens MonthCalendar egenskap. När händelsen DateChanged utlöses Start visas egenskapsvärdena och End i textrutorna. Det här exemplet förutsätter att du har en Form med två TextBox kontroller, en Buttonoch en MonthCalendar kontroll.

private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Create a SelectionRange object and set its Start and End properties.
      SelectionRange^ sr = gcnew SelectionRange;
      sr->Start = DateTime::Parse( this->textBox1->Text );
      sr->End = DateTime::Parse( this->textBox2->Text );
      
      /* Assign the SelectionRange object to the
            SelectionRange property of the MonthCalendar control. */
      this->monthCalendar1->SelectionRange = sr;
   }

   void monthCalendar1_DateChanged( Object^ /*sender*/, DateRangeEventArgs^ /*e*/ )
   {
      /* Display the Start and End property values of
            the SelectionRange object in the text boxes. */
      this->textBox1->Text = monthCalendar1->SelectionRange->Start.Date.ToShortDateString();
      this->textBox2->Text = monthCalendar1->SelectionRange->End.Date.ToShortDateString();
   }
private void button1_Click(object sender, System.EventArgs e)
{
   // Create a SelectionRange object and set its Start and End properties.
   SelectionRange sr = new SelectionRange();
   sr.Start = DateTime.Parse(this.textBox1.Text);
   sr.End = DateTime.Parse(this.textBox2.Text);
   /* Assign the SelectionRange object to the 
      SelectionRange property of the MonthCalendar control. */
   this.monthCalendar1.SelectionRange = sr;
}

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
   /* Display the Start and End property values of 
      the SelectionRange object in the text boxes. */
   this.textBox1.Text = 
     monthCalendar1.SelectionRange.Start.Date.ToShortDateString();
   this.textBox2.Text = 
     monthCalendar1.SelectionRange.End.Date.ToShortDateString();
}
Private Sub button1_Click(sender As Object, _
  e As EventArgs) Handles button1.Click
   ' Create a SelectionRange object and set its Start and End properties.
   Dim sr As New SelectionRange()
   sr.Start = DateTime.Parse(Me.textBox1.Text)
   sr.End = DateTime.Parse(Me.textBox2.Text)
   ' Assign the SelectionRange object to the
   ' SelectionRange property of the MonthCalendar control. 
   Me.monthCalendar1.SelectionRange = sr
End Sub 


Private Sub monthCalendar1_DateChanged(sender As Object, _
  e As DateRangeEventArgs) Handles monthCalendar1.DateChanged
   ' Display the Start and End property values of
   ' the SelectionRange object in the text boxes. 
   Me.textBox1.Text = monthCalendar1.SelectionRange.Start.Date.ToShortDateString()
   Me.textBox2.Text = monthCalendar1.SelectionRange.End.Date.ToShortDateString()
End Sub

Kommentarer

Egenskapsvärdena Start och End tilldelas egenskapsvärdena Start och End för det tilldelade SelectionRange objektet.

Se även

Gäller för

SelectionRange(DateTime, DateTime)

Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs
Källa:
SelectionRange.cs

Initierar en ny instans av SelectionRange klassen med angivna start- och slutdatum.

public:
 SelectionRange(DateTime lower, DateTime upper);
public SelectionRange(DateTime lower, DateTime upper);
new System.Windows.Forms.SelectionRange : DateTime * DateTime -> System.Windows.Forms.SelectionRange
Public Sub New (lower As DateTime, upper As DateTime)

Parametrar

lower
DateTime

Startdatumet i SelectionRange.

upper
DateTime

Slutdatumet SelectionRangei .

Exempel

I följande exempel anges egenskapen för SelectionRange en MonthCalendar kontroll baserat på två datum som anges i två TextBox kontroller när en Button klickas. Den här koden förutsätter att nya instanser av en MonthCalendar kontroll, två TextBox kontroller och en Button har skapats på en Form. Du kan överväga att lägga till kod för att verifiera de Text tilldelade textrutorna för att kontrollera att de innehåller giltiga datum.

private:
   void button1_Click( Object^ sender, EventArgs^ e )
   {
      // Set the SelectionRange with start and end dates from text boxes.
      try
      {
         monthCalendar1->SelectionRange = gcnew SelectionRange(
            DateTime::Parse( textBox1->Text ),
            DateTime::Parse( textBox2->Text ) );
      }
      catch ( Exception^ ex ) 
      {
         MessageBox::Show( ex->Message );
      }
   }
private void button1_Click(object sender,
                           EventArgs e)
{
   // Set the SelectionRange with start and end dates from text boxes.
   try
   {
      monthCalendar1.SelectionRange = new SelectionRange(
        DateTime.Parse(textBox1.Text),
        DateTime.Parse(textBox2.Text));
   }
   catch(Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}
Private Sub button1_Click(sender As Object, e As EventArgs)
   ' Set the SelectionRange with start and end dates from text boxes.
   Try
      monthCalendar1.SelectionRange = New SelectionRange( _
        DateTime.Parse(textBox1.Text), _
        DateTime.Parse(textBox2.Text))
   Catch ex As Exception
      MessageBox.Show(ex.Message)
   End Try
End Sub

Kommentarer

Note

Om värdet lowerDateTime är större än upperDateTime värdet lower tilldelas värdet till End egenskapen i stället för egenskapen Start .

Se även

Gäller för