SelectionRange Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru kelas SelectionRange.
Overload
| SelectionRange() |
Menginisialisasi instans baru kelas SelectionRange. |
| SelectionRange(SelectionRange) |
Menginisialisasi instans baru kelas SelectionRange dengan rentang pilihan yang ditentukan. |
| SelectionRange(DateTime, DateTime) |
Menginisialisasi instans baru kelas SelectionRange dengan tanggal awal dan akhir yang ditentukan. |
SelectionRange()
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
Menginisialisasi instans baru kelas SelectionRange.
public:
SelectionRange();
public SelectionRange();
Public Sub New ()
Contoh
Contoh berikut membuat objek SelectionRange, mengatur properti Start dan End, dan menetapkan objek SelectionRange ke properti SelectionRange kontrol MonthCalendar. Saat peristiwa DateChanged dinaikkan, nilai properti Start dan End ditampilkan dalam kotak teks. Contoh ini mengasumsikan bahwa Anda memiliki Form dengan dua kontrol TextBox, Button, dan kontrol 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
Keterangan
Nilai Start dan End diatur ke null saat konstruktor ini digunakan.
Berlaku untuk
SelectionRange(SelectionRange)
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
Menginisialisasi instans baru kelas SelectionRange dengan rentang pilihan yang ditentukan.
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)
Parameter
- range
- SelectionRange
SelectionRangeyang ada.
Contoh
Contoh berikut membuat objek SelectionRange, mengatur properti Start dan End, dan menetapkan objek SelectionRange ke properti SelectionRange kontrol MonthCalendar. Saat peristiwa DateChanged dinaikkan, nilai properti Start dan End ditampilkan dalam kotak teks. Contoh ini mengasumsikan bahwa Anda memiliki Form dengan dua kontrol TextBox, Button, dan kontrol 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
Keterangan
Nilai properti Start dan End diberi nilai properti Start dan End dari objek SelectionRange yang ditetapkan.
Lihat juga
Berlaku untuk
SelectionRange(DateTime, DateTime)
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
- Sumber:
- SelectionRange.cs
Menginisialisasi instans baru kelas SelectionRange dengan tanggal awal dan akhir yang ditentukan.
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)
Parameter
- lower
- DateTime
Tanggal mulai dalam SelectionRange.
- upper
- DateTime
Tanggal akhir dalam SelectionRange.
Contoh
Contoh berikut mengatur properti SelectionRange kontrol MonthCalendar berdasarkan dua tanggal yang dimasukkan ke dalam dua kontrol TextBox saat Button diklik. Kode ini mengasumsikan instans baru kontrol MonthCalendar, dua kontrol TextBox, dan Button telah dibuat pada Form. Anda mungkin mempertimbangkan untuk menambahkan kode untuk memvalidasi Text yang ditetapkan ke kotak teks untuk memverifikasi bahwa kode tersebut berisi tanggal yang valid.
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
Keterangan
Nota
Jika nilai lowerDateTime lebih besar dari nilai upperDateTime, nilai lower akan ditetapkan ke properti End alih-alih properti Start.