SelectionRange Konstruktoren

Definition

Initialisiert eine neue Instanz der SelectionRange-Klasse.

Überlädt

SelectionRange()

Initialisiert eine neue Instanz der SelectionRange-Klasse.

SelectionRange(SelectionRange)

Initialisiert eine neue Instanz der SelectionRange-Klasse mit dem angegebenen Auswahlbereich.

SelectionRange(DateTime, DateTime)

Initialisiert eine neue Instanz der SelectionRange-Klasse mit dem angegebenen Anfangs- und Enddatum.

SelectionRange()

Initialisiert eine neue Instanz der SelectionRange-Klasse.

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

Beispiele

Im folgenden Beispiel wird ein SelectionRange -Objekt erstellt, dessen Start Eigenschaften und festgelegt End und das SelectionRange -Objekt der SelectionRange -Eigenschaft des MonthCalendar -Steuerelements zugewiesen. Wenn das DateChanged Ereignis ausgelöst wird, werden die Start Eigenschaftswerte und End in den Textfeldern angezeigt. In diesem Beispiel wird davon ausgegangen, dass Sie über ein Form -Steuerelement mit zwei TextBox -Steuerelementen verfügen, einem Button- und einem MonthCalendar -Steuerelement.

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

Hinweise

Die Start Werte und End werden auf null festgelegt, wenn dieser Konstruktor verwendet wird.

Gilt für:

SelectionRange(SelectionRange)

Initialisiert eine neue Instanz der SelectionRange-Klasse mit dem angegebenen Auswahlbereich.

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)

Parameter

range
SelectionRange

Der vorhandene SelectionRange.

Beispiele

Im folgenden Beispiel wird ein SelectionRange -Objekt erstellt, dessen Start Eigenschaften und festgelegt End und das SelectionRange -Objekt der SelectionRange -Eigenschaft des MonthCalendar -Steuerelements zugewiesen. Wenn das DateChanged Ereignis ausgelöst wird, werden die Start Eigenschaftswerte und End in den Textfeldern angezeigt. In diesem Beispiel wird davon ausgegangen, dass Sie über ein Form -Steuerelement mit zwei TextBox -Steuerelementen verfügen, einem Button- und einem MonthCalendar -Steuerelement.

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

Hinweise

Den Start Eigenschaftswerten und End werden die Start Eigenschaftenwerte und End des zugewiesenen SelectionRange Objekts zugewiesen.

Weitere Informationen

Gilt für:

SelectionRange(DateTime, DateTime)

Initialisiert eine neue Instanz der SelectionRange-Klasse mit dem angegebenen Anfangs- und Enddatum.

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)

Parameter

lower
DateTime

Das Startdatum in SelectionRange.

upper
DateTime

Das Enddatum in SelectionRange.

Beispiele

Im folgenden Beispiel wird die SelectionRange -Eigenschaft eines MonthCalendar Steuerelements basierend auf zwei Datumsangaben festgelegt, die in zwei TextBox Steuerelementen eingegeben werden, wenn auf ein Button -Steuerelement geklickt wird. Bei diesem Code wird davon ausgegangen, dass neue Instanzen eines MonthCalendar -Steuerelements, zwei TextBox -Steuerelemente und ein Button -Steuerelement auf einem Formerstellt wurden. Sie können erwägen, Code hinzuzufügen, um das Text den Textfeldern zugewiesene zu überprüfen, um zu überprüfen, ob sie gültige Datumsangaben enthalten.

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

Hinweise

Hinweis

Wenn der lowerDateTime Wert größer als der upperDateTime Wert ist, wird der lower Wert der End -Eigenschaft anstelle der Start -Eigenschaft zugewiesen.

Weitere Informationen

Gilt für: