DateTimePickerFormat Enumeration
Specifies the date and time format the DateTimePicker control displays.
[Visual Basic] <Serializable> Public Enum DateTimePickerFormat [C#] [Serializable] public enum DateTimePickerFormat [C++] [Serializable] __value public enum DateTimePickerFormat [JScript] public Serializable enum DateTimePickerFormat
Remarks
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.
Members
| 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. |
Example
[Visual Basic, C#] The following code example demonstrates initializing a DateTimePicker using the DateTimePickerFormat enumeration. To run this example paste the following code in a form and call InitializeDateTimePicker from the form's constructor or load method.
[Visual Basic] ' 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 [C#] // Declare the DateTimePicker. internal System.Windows.Forms.DateTimePicker DateTimePicker1; private void InitializeDateTimePicker() { // Construct the DateTimePicker. this.DateTimePicker1 = new System.Windows.Forms.DateTimePicker(); //Set size and location. this.DateTimePicker1.Location = new System.Drawing.Point(40, 88); this.DateTimePicker1.Size = new System.Drawing.Size(160, 21); // Set the alignment of the drop-down MonthCalendar to right. this.DateTimePicker1.DropDownAlign = LeftRightAlignment.Right; // Set the Value property to 50 years before today. DateTimePicker1.Value = System.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. this.Controls.Add(this.DateTimePicker1); }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Windows.Forms
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)