DropDownAlign Property

DateTimePicker.DropDownAlign Property

 

Gets or sets the alignment of the drop-down calendar on the DateTimePicker control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public LeftRightAlignment DropDownAlign { get; set; }

Property Value

Type: System.Windows.Forms.LeftRightAlignment

The alignment of the drop-down calendar on the control. The default is Left.

Exception Condition
InvalidEnumArgumentException

The value assigned is not one of the LeftRightAlignment values.

The drop-down calendar can be aligned to the left or right of the control.

The following code example demonstrates initializing a DateTimePicker by setting the DropDownAlign, Value, Format, and CustomFormat properties. To run this example, paste the following code into 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);
}

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft