SelectionRange SelectionRange SelectionRange SelectionRange Class

定义

表示月历控件中的日期选择范围。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
继承
SelectionRangeSelectionRangeSelectionRangeSelectionRange
属性

示例

下面的示例设置SelectionRange的属性MonthCalendar控制基于为两个输入的两个日期TextBox控制何时Button单击。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. SelectionRange可以更改用户单击某个日期并同时将鼠标指针拖过所需的日期,或者可以在代码中设置范围。The 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() SelectionRange() SelectionRange()

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

SelectionRange(DateTime, DateTime) SelectionRange(DateTime, DateTime) SelectionRange(DateTime, DateTime) SelectionRange(DateTime, DateTime)

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

SelectionRange(SelectionRange) SelectionRange(SelectionRange) SelectionRange(SelectionRange) SelectionRange(SelectionRange)

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

属性

End End End End

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

Start Start Start Start

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

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

适用于

另请参阅