Share via


Como: Usar a classe DateTimePicker no .NET Compact estrutura

The .NET Compact Framework oferece suporte a DateTimePicker classe, mas com apenas os seguintes membros:

Observe que, como OnValueChanged é fornecida uma classe derivada pode usar esse método sem ter que conectar um delegado manipulador de eventos. Para obter mais informações sobre como usar delegados, consulte Gerando um evento.

Observação:

O DateTimePicker para o Smartphone está disponível no Windows Mobile software versão 5.0 para Smartphone. O controle no Smartphone não tem o seletor para cima para baixo porque valores foram selecionados com as teclas de navegação.

Exemplo

O exemplo de código a seguir mostra como você pode configurar um DateTimePicker controlar no .NET Compact Framework.

Private Sub SetupDateTimePicker()
   ' Set the MinDate and MaxDate.
   DateTimePicker1.MinDate = new DateTime(1985, 6, 12)
   DateTimePicker1.MaxDate = DateTime.Today

   'Set the format.
   DateTimePicker1.Format = DateTimePickerFormat.Short

   ' Define a custom format.
   DateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"

   ' If you want to use the custom format, change
   ' DateTimePickerFormat.Short to DateTimePickerFormat.Custom.

   ' Display the control with the up-down selector.
    DateTimePicker1.ShowUpDown = True

End Sub

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    ' Respond to changes, such as using  
    ' the updated value in your application.
End Sub
private void SetupDateTimePicker()
{

   // Set the MinDate and MaxDate.
   dateTimePicker1.MinDate = new DateTime(1985, 6, 12);
   dateTimePicker1.MaxDate = DateTime.Today;

   // Set the format.
   dateTimePicker1.Format = DateTimePickerFormat.Short;

   // Define a custom format.
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";

   // If you want to use the custom format, change
   // DateTimePickerFormat.Short to DateTimePickerFormat.Custom.

   // Display the control with the up-down selector.
   dateTimePicker1.ShowUpDown = true;
}

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
 // Respond to changes, such as using
 // the updated value in your application.

}

Compilando o código

Este exemplo requer referências aos seguintes namespaces:

Consulte também

Outros recursos

Controles Windows Forms no .NET Windows Compact Framework

Elementos gráficos e desenho no .NET Compact estrutura