Compartir vía


DateTimePicker.Value Propiedad

Definición

Obtiene o establece el valor de fecha y hora asignado al control .

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

Valor de propiedad

Valor DateTime asignado al control.

Atributos

Excepciones

El valor establecido es menor MinDate o más que MaxDate.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la Value propiedad para recuperar el valor de fecha actual. En primer lugar, el ejemplo muestra la Value propiedad . A continuación, el ejemplo incrementa la Value propiedad en un día y muestra de nuevo el valor de la propiedad.

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

Comentarios

Si el usuario no ha cambiado la Value propiedad o en el código, se establece en la fecha y hora actuales (DateTime.Now).

Se aplica a

Consulte también