SelectionRange 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 SelectionRange 类的新实例。
重载
SelectionRange() |
初始化 SelectionRange 类的新实例。 |
SelectionRange(SelectionRange) |
使用指定的选择范围初始化 SelectionRange 类的新实例。 |
SelectionRange(DateTime, DateTime) |
使用指定的起始和结束日期初始化 SelectionRange 类的新实例。 |
SelectionRange()
初始化 SelectionRange 类的新实例。
public:
SelectionRange();
public SelectionRange ();
Public Sub New ()
示例
以下示例创建一个 SelectionRange 对象,设置其 Start 和 End 属性,并将 对象SelectionRangeSelectionRange分配给控件MonthCalendar的 属性。 DateChanged引发事件时,Start和 End 属性值将显示在文本框中。 此示例假定你有 一个具有两TextBox个FormButton控件的 , 和 一个MonthCalendar控件。
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
注解
使用此构造函数时, Start 和 End 值设置为 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)
参数
- range
- SelectionRange
现有的 SelectionRange。
示例
以下示例创建一个 SelectionRange 对象,设置其 Start 和 End 属性,并将 对象SelectionRangeSelectionRange分配给控件MonthCalendar的 属性。 DateChanged引发事件时,Start和 End 属性值将显示在文本框中。 此示例假定你有 一个具有两TextBox个FormButton控件的 , 和 一个MonthCalendar控件。
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
注解
为 Start 和 End 属性值分配了Start所SelectionRange分配对象的 和 End 属性值。
另请参阅
适用于
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 中的结束日期。
示例
以下示例基于单击 时输入到两个MonthCalendar控件中的两个Button日期设置SelectionRange控件TextBox的 属性。 此代码假定已在 上创建了一个MonthCalendar控件的新实例、两TextBox个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
注解
另请参阅
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈