다음을 통해 공유


SelectionRange 생성자

정의

SelectionRange 클래스의 새 인스턴스를 초기화합니다.

오버로드

SelectionRange()

SelectionRange 클래스의 새 인스턴스를 초기화합니다.

SelectionRange(SelectionRange)

지정된 선택 범위를 사용하여 SelectionRange 클래스의 새 인스턴스를 초기화합니다.

SelectionRange(DateTime, DateTime)

지정된 시작 날짜와 종료 날짜를 사용하여 SelectionRange 클래스의 새 인스턴스를 초기화합니다.

SelectionRange()

SelectionRange 클래스의 새 인스턴스를 초기화합니다.

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

예제

다음 예제에서는 SelectionRange 개체를 만들고, StartEnd 속성을 설정하고, SelectionRange 개체를 MonthCalendar 컨트롤의 SelectionRange 속성에 할당합니다. DateChanged 이벤트가 발생하면 텍스트 상자에 StartEnd 속성 값이 표시됩니다. 이 예제에서는 두 개의 TextBox 컨트롤, ButtonMonthCalendar 컨트롤이 있는 Form 있다고 가정합니다.

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

설명

StartEnd 값은 이 생성자를 사용할 때 null 설정됩니다.

적용 대상

SelectionRange(SelectionRange)

지정된 선택 범위를 사용하여 SelectionRange 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

예제

다음 예제에서는 SelectionRange 개체를 만들고, StartEnd 속성을 설정하고, SelectionRange 개체를 MonthCalendar 컨트롤의 SelectionRange 속성에 할당합니다. DateChanged 이벤트가 발생하면 텍스트 상자에 StartEnd 속성 값이 표시됩니다. 이 예제에서는 두 개의 TextBox 컨트롤, ButtonMonthCalendar 컨트롤이 있는 Form 있다고 가정합니다.

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

설명

StartEnd 속성 값에는 할당된 SelectionRange 개체의 StartEnd 속성 값이 할당됩니다.

추가 정보

적용 대상

SelectionRange(DateTime, DateTime)

지정된 시작 날짜와 종료 날짜를 사용하여 SelectionRange 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

lower
DateTime

SelectionRange시작 날짜입니다.

upper
DateTime

SelectionRange종료 날짜입니다.

예제

다음은 Button 클릭할 때 두 개의 TextBox 컨트롤에 입력한 두 날짜를 기준으로 MonthCalendar 컨트롤의 SelectionRange 속성을 설정하는 예제입니다. 이 코드는 MonthCalendar 컨트롤의 새 인스턴스, 두 개의 TextBox 컨트롤 및 ButtonForm만든 것으로 가정합니다. 텍스트 상자에 할당된 Text 유효한 날짜가 포함되어 있는지 확인하는 코드를 추가하는 것이 좋습니다.

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

설명

메모

lower DateTime 값이 upperDateTime 값보다 크면 lower 값이 Start 속성 대신 End 속성에 할당됩니다.

추가 정보

적용 대상