Bagikan melalui


DateTimePicker.Value Properti

Definisi

Mendapatkan atau mengatur nilai tanggal/waktu yang ditetapkan ke kontrol.

public:
 property DateTime Value { DateTime get(); void set(DateTime value); };
[System.ComponentModel.Bindable(true)]
public DateTime Value { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Value : DateTime with get, set
Public Property Value As DateTime

Nilai Properti

Nilai DateTime yang ditetapkan ke kontrol.

Atribut

Pengecualian

Nilai yang ditetapkan kurang dari MinDate atau lebih dari MaxDate.

Contoh

Contoh kode berikut menunjukkan cara menggunakan Value properti untuk mengambil nilai tanggal saat ini. Pertama, contoh menampilkan Value properti . Contoh kemudian menaikkan Value properti satu hari dan menampilkan nilai properti lagi.

public:
   MyClass()
   {
      // Create a new DateTimePicker
      DateTimePicker^ dateTimePicker1 = gcnew DateTimePicker;
      array<Control^>^ myClassControls = {dateTimePicker1};
      Controls->AddRange( myClassControls );
      MessageBox::Show( dateTimePicker1->Value.ToString() );

      dateTimePicker1->Value = DateTime::Now.AddDays( 1 );
      MessageBox::Show( dateTimePicker1->Value.ToString() );
   }
public MyClass()
{
   // Create a new DateTimePicker
   DateTimePicker dateTimePicker1 = new DateTimePicker();
   Controls.AddRange(new Control[] {dateTimePicker1});
   MessageBox.Show(dateTimePicker1.Value.ToString());

   dateTimePicker1.Value = DateTime.Now.AddDays(1);
   MessageBox.Show(dateTimePicker1.Value.ToString());
}
Public Sub New()
   ' Create a new DateTimePicker
   Dim dateTimePicker1 As New DateTimePicker()
   Controls.AddRange(New Control() {dateTimePicker1})
   MessageBox.Show(dateTimePicker1.Value.ToString())
   
   dateTimePicker1.Value = DateTime.Now.AddDays(1)
   MessageBox.Show(dateTimePicker1.Value.ToString())
End Sub

Keterangan

Value Jika properti belum diubah dalam kode atau oleh pengguna, properti diatur ke tanggal dan waktu saat ini (DateTime.Now).

Berlaku untuk

Lihat juga