SelectionRange 類別

定義

表示在月曆控制項中的資料選取範圍。

public ref class SelectionRange sealed
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.SelectionRangeConverter))]
public sealed class SelectionRange
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.SelectionRangeConverter))>]
type SelectionRange = class
Public NotInheritable Class SelectionRange
繼承
SelectionRange
屬性

範例

下列範例會根據按一下 時輸入 TextBox 兩個控制項的 Button 兩個 MonthCalendar 日期,設定 SelectionRange 控制項的 屬性。 此程式碼假設控制項的新實例、兩 TextBoxMonthCalendar 控制項,以及 Button 已在 上 Form 建立 。 您可以考慮新增程式碼來驗證 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

備註

SelectionRange是選取的日期或日期,並在控制項上 MonthCalendar 反白顯示。 如果只選取一個日期, StartEnd 屬性值將會相等。 SelectionRange使用者可以按一下日期來變更 ,同時拖曳滑鼠指標到所需的日期,或者您可以在程式碼中設定範圍。 例如,您可能想要讓使用者將日期範圍輸入兩 TextBox 個控制項或兩 DateTimePicker 個控制項,並根據這些日期來設定 SelectionRange

建構函式

SelectionRange()

初始化 SelectionRange 類別的新執行個體。

SelectionRange(DateTime, DateTime)

使用指定的開始和結束日期來初始化 SelectionRange 類別的新執行個體。

SelectionRange(SelectionRange)

使用指定的選取範圍來初始化 SelectionRange 類別的新執行個體。

屬性

End

取得或設定選取範圍的結束日期和時間。

Start

取得或設定選取範圍的開始日期和時間。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回表示 SelectionRange 的字串。

適用於

另請參閱