Share via


SelectionRange Oluşturucular

Tanım

SelectionRange sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

SelectionRange()

SelectionRange sınıfının yeni bir örneğini başlatır.

SelectionRange(SelectionRange)

Belirtilen seçim aralığıyla sınıfının yeni bir örneğini SelectionRange başlatır.

SelectionRange(DateTime, DateTime)

Belirtilen başlangıç ve bitiş tarihleriyle sınıfının yeni bir örneğini SelectionRange başlatır.

SelectionRange()

SelectionRange sınıfının yeni bir örneğini başlatır.

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

Örnekler

Aşağıdaki örnek bir SelectionRange nesne oluşturur, nesnesini Start ve End özelliklerini ayarlar ve nesneyi denetimin SelectionRangeMonthCalendar özelliğine atarSelectionRange. DateChanged Olay tetiklendiğinde ve StartEnd özellik değerleri metin kutularında görüntülenir. Bu örnekte, iki TextBox denetime sahip bir Form denetiminiz olduğu varsayılır: bir Buttonve bir MonthCalendar denetim.

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

Açıklamalar

Start Bu oluşturucu kullanıldığında ve End değerleri olarak null ayarlanır.

Şunlara uygulanır

SelectionRange(SelectionRange)

Belirtilen seçim aralığıyla sınıfının yeni bir örneğini SelectionRange başlatır.

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)

Parametreler

range
SelectionRange

Var olan SelectionRange.

Örnekler

Aşağıdaki örnek bir SelectionRange nesne oluşturur, nesnesini Start ve End özelliklerini ayarlar ve nesneyi denetimin SelectionRangeMonthCalendar özelliğine atarSelectionRange. DateChanged Olay tetiklendiğinde ve StartEnd özellik değerleri metin kutularında görüntülenir. Bu örnekte, iki TextBox denetime sahip bir Form denetiminiz olduğu varsayılır: bir Buttonve bir MonthCalendar denetim.

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

Açıklamalar

Start ve End özellik değerleri, atanan nesnenin Start ve End özellik değerlerine atanırSelectionRange.

Ayrıca bkz.

Şunlara uygulanır

SelectionRange(DateTime, DateTime)

Belirtilen başlangıç ve bitiş tarihleriyle sınıfının yeni bir örneğini SelectionRange başlatır.

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)

Parametreler

lower
DateTime

içindeki SelectionRangebaşlangıç tarihi.

upper
DateTime

içindeki SelectionRangebitiş tarihi.

Örnekler

Aşağıdaki örnek, bir MonthCalendar denetimin özelliğini, tıklandığında Button iki denetime girilen iki TextBox tarihe göre ayarlarSelectionRange. Bu kod, bir MonthCalendar denetimin yeni örneklerinin, iki TextBox denetimin ve üzerinde bir Button öğesinin oluşturulduğunu Formvarsayar. Geçerli tarihler içerdiğini doğrulamak Text için metin kutularına atananları doğrulamak için kod eklemeyi düşünebilirsiniz.

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

Açıklamalar

Not

lowerDateTime Değer değerdenDateTimeupperbüyükse, lower değer özelliği yerine özelliğine EndStart atanır.

Ayrıca bkz.

Şunlara uygulanır