Export (0) Print
Expand All
Expand Minimize
1 out of 2 rated this helpful - Rate this topic

DateTimePickerFormat Enumeration

Specifies the date and time format the DateTimePicker control displays.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public enum DateTimePickerFormat
Member nameDescription
Supported by the .NET Compact FrameworkLongThe DateTimePicker control displays the date/time value in the long date format set by the user's operating system.
Supported by the .NET Compact FrameworkShortThe DateTimePicker control displays the date/time value in the short date format set by the user's operating system.
Supported by the .NET Compact FrameworkTimeThe DateTimePicker control displays the date/time value in the time format set by the user's operating system.
Supported by the .NET Compact FrameworkCustomThe DateTimePicker control displays the date/time value in a custom format. For more information, see CustomFormat.

This enumeration is used by members such as DateTimePicker.Format.

NoteNote:

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. 
	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);
	}
	DateTimePicker object by setting the DropDownAlign, Value, Format, and 
	CustomFormat properties.  To run this example paste the following
	code in a form containing a DateTimePicker named DateTimePicker1.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.