Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


SelectionRange Constructors

Definition

Initializes a new instance of the SelectionRange class.

Overloads

SelectionRange()

Initializes a new instance of the SelectionRange class.

SelectionRange(SelectionRange)

Initializes a new instance of the SelectionRange class with the specified selection range.

SelectionRange(DateTime, DateTime)

Initializes a new instance of the SelectionRange class with the specified beginning and ending dates.

SelectionRange()

Source:
SelectionRange.cs
Source:
SelectionRange.cs
Source:
SelectionRange.cs

Initializes a new instance of the SelectionRange class.

public SelectionRange ();

Examples

The following example creates a SelectionRange object, sets its Start and End properties, and assigns the SelectionRange object to the SelectionRange property of the MonthCalendar control. When the DateChanged event is raised, the Start and End property values are displayed in the text boxes. This example assumes that you have a Form with two TextBox controls, a Button, and a MonthCalendar control.

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();
}

Remarks

The Start and End values are set to null when this constructor is used.

Applies to

.NET Framework 4.8.1 és más verziók
Termék Verziók
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

SelectionRange(SelectionRange)

Source:
SelectionRange.cs
Source:
SelectionRange.cs
Source:
SelectionRange.cs

Initializes a new instance of the SelectionRange class with the specified selection range.

public SelectionRange (System.Windows.Forms.SelectionRange range);

Parameters

range
SelectionRange

The existing SelectionRange.

Examples

The following example creates a SelectionRange object, sets its Start and End properties, and assigns the SelectionRange object to the SelectionRange property of the MonthCalendar control. When the DateChanged event is raised, the Start and End property values are displayed in the text boxes. This example assumes that you have a Form with two TextBox controls, a Button, and a MonthCalendar control.

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();
}

Remarks

The Start and End property values are assigned the Start and End property values of the assigned SelectionRange object.

See also

Applies to

.NET Framework 4.8.1 és más verziók
Termék Verziók
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

SelectionRange(DateTime, DateTime)

Source:
SelectionRange.cs
Source:
SelectionRange.cs
Source:
SelectionRange.cs

Initializes a new instance of the SelectionRange class with the specified beginning and ending dates.

public SelectionRange (DateTime lower, DateTime upper);

Parameters

lower
DateTime

The starting date in the SelectionRange.

upper
DateTime

The ending date in the SelectionRange.

Examples

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. This code assumes new instances of a MonthCalendar control, two TextBox controls, and a Button have been created on a Form. 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 = new SelectionRange(
        DateTime.Parse(textBox1.Text),
        DateTime.Parse(textBox2.Text));
   }
   catch(Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}

Remarks

Megjegyzés

If the lower DateTime value is greater than the upper DateTime value, the lower value will be assigned to the End property instead of the Start property.

See also

Applies to

.NET Framework 4.8.1 és más verziók
Termék Verziók
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9