DateTimePickerFormat Enumeration
Assembly: System.Windows.Forms (in system.windows.forms.dll)
| Member name | Description | |
|---|---|---|
![]() | Custom | The DateTimePicker control displays the date/time value in a custom format. |
![]() | Long | The DateTimePicker control displays the date/time value in the long date format set by the user's operating system. |
![]() | Short | The DateTimePicker control displays the date/time value in the short date format set by the user's operating system. |
![]() | Time | The DateTimePicker control displays the date/time value in the time format set by the user's operating system. |
This enumeration is used by members such as DateTimePicker.Format.
Note |
|---|
| The actual date/time formats are determined by the date, time, and regional settings set in the user's operating system. |
The following code example demonstrates initializing a DateTimePicker object by setting the Format to a DateTimePickerFormat value. To run this example paste the following code in a form and call InitializeDateTimePicker from the form's constructor or Load event-handling method.
' Declare the DateTimePicker. Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker Private Sub InitializeDateTimePicker() ' Construct the DateTimePicker. Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker 'Set size and location. Me.DateTimePicker1.Location = New System.Drawing.Point(40, 88) Me.DateTimePicker1.Size = New Size(160, 21) ' Set the alignment of the drop-down MonthCalendar to right. Me.DateTimePicker1.DropDownAlign = LeftRightAlignment.Right ' Set the Value property to 50 years before today. DateTimePicker1.Value = (DateTime.Now.AddYears(-50)) 'Set a custom format containing the string "of the year" DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = "MMM dd, 'of the year' yyyy " ' Add the DateTimePicker to the form. Me.Controls.Add(Me.DateTimePicker1) End Sub
// Declare the DateTimePicker.
private System.Windows.Forms.DateTimePicker dateTimePicker1;
private void InitializeDateTimePicker()
{
// Construct the DateTimePicker.
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
//Set size and location.
this.dateTimePicker1.set_Location(new System.Drawing.Point(40, 88));
this.dateTimePicker1.set_Size(new System.Drawing.Size(160, 21));
// Set the alignment of the drop-down MonthCalendar to right.
this.dateTimePicker1.set_DropDownAlign(LeftRightAlignment.Right);
// Set the Value property to 50 years before today.
dateTimePicker1.set_Value(System.DateTime.get_Now().AddYears(-50));
//Set a custom format containing the string "of the year"
dateTimePicker1.set_Format(DateTimePickerFormat.Custom);
dateTimePicker1.set_CustomFormat("MMM dd, 'of the year' yyyy ");
// Add the DateTimePicker to the form.
this.get_Controls().Add(this.dateTimePicker1);
} //InitializeDateTimePicker
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
