Condividi tramite


SelectionRange Costruttori

Definizione

Inizializza una nuova istanza della classe SelectionRange.

Overload

Nome Descrizione
SelectionRange()

Inizializza una nuova istanza della classe SelectionRange.

SelectionRange(SelectionRange)

Inizializza una nuova istanza della SelectionRange classe con l'intervallo di selezione specificato.

SelectionRange(DateTime, DateTime)

Inizializza una nuova istanza della SelectionRange classe con le date di inizio e fine specificate.

SelectionRange()

Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs

Inizializza una nuova istanza della classe SelectionRange.

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

Esempio

Nell'esempio seguente viene creato un SelectionRange oggetto , vengono impostate le Start relative proprietà e End e viene assegnato l'oggetto SelectionRange alla SelectionRange proprietà del MonthCalendar controllo . Quando viene generato l'evento DateChanged , i valori delle Start proprietà e End vengono visualizzati nelle caselle di testo. In questo esempio si presuppone che sia presente un Form oggetto con due TextBox controlli, un Buttone un MonthCalendar controllo .

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

Commenti

I Start valori e End vengono impostati su null quando viene usato questo costruttore.

Si applica a

SelectionRange(SelectionRange)

Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs

Inizializza una nuova istanza della SelectionRange classe con l'intervallo di selezione specificato.

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)

Parametri

range
SelectionRange

Oggetto esistente SelectionRange.

Esempio

Nell'esempio seguente viene creato un SelectionRange oggetto , vengono impostate le Start relative proprietà e End e viene assegnato l'oggetto SelectionRange alla SelectionRange proprietà del MonthCalendar controllo . Quando viene generato l'evento DateChanged , i valori delle Start proprietà e End vengono visualizzati nelle caselle di testo. In questo esempio si presuppone che sia presente un Form oggetto con due TextBox controlli, un Buttone un MonthCalendar controllo .

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

Commenti

Ai Start valori della proprietà e vengono assegnati i Start valori delle proprietà e EndEnd dell'oggetto assegnatoSelectionRange.

Vedi anche

Si applica a

SelectionRange(DateTime, DateTime)

Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs
Origine:
SelectionRange.cs

Inizializza una nuova istanza della SelectionRange classe con le date di inizio e fine specificate.

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)

Parametri

lower
DateTime

Data di inizio in SelectionRange.

upper
DateTime

Data di fine nell'oggetto SelectionRange.

Esempio

Nell'esempio seguente viene impostata la SelectionRange proprietà di un MonthCalendar controllo in base a due date immesse in due TextBox controlli quando si fa clic su un Button controllo . Questo codice presuppone che le nuove istanze di un MonthCalendar controllo, due TextBox controlli e un controllo Button siano stati creati in un oggetto Form. È possibile aggiungere codice per convalidare l'oggetto Text assegnato alle caselle di testo per verificare che contengano date valide.

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

Commenti

Nota

Se il lowerDateTime valore è maggiore delDateTimeuppervalore, il lower valore verrà assegnato alla End proprietà anziché alla Start proprietà .

Vedi anche

Si applica a