SelectionRange 类

定义

表示月历控件中的日期选择范围。Represents a date selection range in a month calendar control.

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

示例

下面的示例根据在SelectionRange单击时Button输入MonthCalendar到两个TextBox控件中的两个日期, 设置控件的属性。The following example sets the SelectionRange property of a MonthCalendar control based on two dates entered into two TextBox controls when a Button is clicked. 此代码MonthCalendar假设已在上TextBox Button创建控件、两个控件和的新实例。 FormThis code assumes new instances of a MonthCalendar control, two TextBox controls, and a Button have been created on a Form. 您可以考虑添加代码以验证指定Text的文本框, 以验证它们是否包含有效日期。You might consider adding code to validate the Text assigned to the text boxes to verify that they contain valid dates.

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上选定和突出显示的日期或日期。The SelectionRange is the date or dates selected and highlighted on the MonthCalendar control. 如果仅选择了一个日期, 则StartEnd属性值将相等。If only one date is selected, the Start and End property values will be equal. 在将鼠标指针拖动到所需的日期时, 用户可以通过单击日期来更改,也可以在代码中设置范围。SelectionRangeThe SelectionRange can be changed by the user clicking a date while dragging the mouse pointer across the desired dates, or you can set the range in code. 例如, 您可能希望让用户将日期范围输入到两个TextBox控件或两个DateTimePicker控件中, 并SelectionRange基于这些日期设置。For example, you might want to have the user enter a date range into two TextBox controls or two DateTimePicker controls and set the SelectionRange based on those dates.

构造函数

SelectionRange()

初始化 SelectionRange 类的新实例。Initializes a new instance of the SelectionRange class.

SelectionRange(DateTime, DateTime)

使用指定的起始和结束日期初始化 SelectionRange 类的新实例。Initializes a new instance of the SelectionRange class with the specified beginning and ending dates.

SelectionRange(SelectionRange)

使用指定的选择范围初始化 SelectionRange 类的新实例。Initializes a new instance of the SelectionRange class with the specified selection range.

属性

End

获取或设置选择范围的结束日期和时间。Gets or sets the ending date and time of the selection range.

Start

获取或设置选择范围的起始日期和时间。Gets or sets the starting date and time of the selection range.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示 SelectionRange 的字符串。Returns a string that represents the SelectionRange.

适用于

另请参阅