Freigeben über


SelectionRange Konstruktoren

Definition

Initialisiert eine neue Instanz der SelectionRange-Klasse.

Überlädt

Name Beschreibung
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()

Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs

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 End Eigenschaften festgelegt und dem SelectionRange Objekt die SelectionRange Eigenschaft des MonthCalendar Steuerelements zugewiesen. Wenn das DateChanged Ereignis ausgelöst wird, werden die Start Werte und End Eigenschaftenwerte in den Textfeldern angezeigt. In diesem Beispiel wird davon ausgegangen, dass Sie über zwei FormTextBox Steuerelemente, ein Buttonund ein MonthCalendar Steuerelement verfügen.

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 Werte End und Werte Start werden festgelegtnull, wenn dieser Konstruktor verwendet wird.

Gilt für:

SelectionRange(SelectionRange)

Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs

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

Die vorhandene SelectionRange.

Beispiele

Im folgenden Beispiel wird ein SelectionRange Objekt erstellt, dessen Start Eigenschaften und End Eigenschaften festgelegt und dem SelectionRange Objekt die SelectionRange Eigenschaft des MonthCalendar Steuerelements zugewiesen. Wenn das DateChanged Ereignis ausgelöst wird, werden die Start Werte und End Eigenschaftenwerte in den Textfeldern angezeigt. In diesem Beispiel wird davon ausgegangen, dass Sie über zwei FormTextBox Steuerelemente, ein Buttonund ein MonthCalendar Steuerelement verfügen.

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 Werten und End Eigenschaften werden die Start Werte und End Eigenschaftenwerte des zugewiesenen Objekts zugewiesen SelectionRange .

Weitere Informationen

Gilt für:

SelectionRange(DateTime, DateTime)

Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs
Quelle:
SelectionRange.cs

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 der SelectionRange.

upper
DateTime

Das Enddatum in der SelectionRange.

Beispiele

Im folgenden Beispiel wird die SelectionRange Eigenschaft eines MonthCalendar Steuerelements basierend auf zwei Datumsangaben festgelegt, die in zwei TextBox Steuerelemente eingegeben wurden, wenn auf ein Button Steuerelement geklickt wird. Dieser Code setzt voraus, dass neue Instanzen eines MonthCalendar Steuerelements, zwei TextBox Steuerelemente und ein Button Steuerelement für ein FormSteuerelement erstellt wurden. Möglicherweise können Sie Code hinzufügen, um die Text zugewiesenen Textfelder zu überprüfen, um sicherzustellen, dass 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

Anmerkung

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

Weitere Informationen

Gilt für: