Edit

Share via


DateTimePickerFormat Enum

Definition

Specifies the date and time format the DateTimePicker control displays.

C#
public enum DateTimePickerFormat
Inheritance
DateTimePickerFormat

Fields

Name Value Description
Long 1

The DateTimePicker control displays the date/time value in the long date format set by the user's operating system.

Short 2

The DateTimePicker control displays the date/time value in the short date format set by the user's operating system.

Time 4

The DateTimePicker control displays the date/time value in the time format set by the user's operating system.

Custom 8

The DateTimePicker control displays the date/time value in a custom format. For more information, see CustomFormat.

Examples

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.

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);
}

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.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also