Open In App

C# | DateTimePicker Class

In Windows Forms, the DateTimePicker control is used to select and display the date/time with a specific format in your form. The FlowLayoutPanel class is used to represent windows DateTimePicker control and also provide different types of properties, methods, and events. It is defined under System.Windows.Forms namespace. You can create two different types of DateTimePicker, as a drop-down list with a date represented in the text, or as a calendar which appears when you click on the down-arrow next to the given list. In C#, you can create a DateTimePicker in the windows form by using two different ways:

1. Design-Time: It is the easiest way to create a DateTimePicker control as shown in the following steps:



2. Run-Time: It is a little bit trickier than the above method. In this method, you can create a DateTimePicker programmatically with the help of syntax provided by the DateTimePicker class. The following steps show how to set the create DateTimePicker dynamically:

Constructor

Constructor Description
DateTimePicker() This constructor is used to initializes a new instance of the DateTimePicker class.

Fields

Fields Description
DefaultMonthBackColor This is field specifies the default month background color of the DateTimePicker control. This field is read-only.
DefaultTitleBackColor This is field specifies the default title back color of the DateTimePicker control. This field is read-only.
DefaultTitleForeColor This is field specifies the default title foreground color of the DateTimePicker control. This field is read-only.
DefaultTrailingForeColor This is field specifies the default trailing foreground color of the DateTimePicker control. This field is read-only.
MaxDateTime This is field specifies the maximum date value of the DateTimePicker control. This field is read-only.
MinDateTime This is field get the minimum date value of the DateTimePicker control.

Properties

Property Description
AutoSize This property is used to get or set a value that indicates whether the control resizes based on its contents.
AutoSizeMode This property indicates the automatic sizing behavior of the control.
BackColor This property is used to get or set the background color for the control.
BorderStyle This property indicates the border style for the control.
CalendarFont This property is used to get or set the font style applied to the calendar.
CalendarForeColor This property is used to get or set the foreground color of the calendar.
CalendarMonthBackground This property is used to get or set the background color of the calendar month.
CalendarTitleBackColor This property is used to get or set the background color of the calendar title.
CalendarTitleForeColor This property is used to get or set the foreground color of the calendar title.
CalendarTrailingForeColor This property is used to get or set the foreground color of the calendar trailing dates.
Font This property is used to get or set the font of the text displayed by the control.
ForeColor This property is used to get or set the foreground color of the control.
Format This property is used to get or set the format of the date and time displayed in the control.
Height This property is used to get or set the height of the control.
Location This property is used to get or set the coordinates of the upper-left corner of the DateTimePicker control relative to the upper-left corner of its form.
MaxDate This property is used to get or set the maximum date and time that can be selected in the control.
MaximumDateTime This property is used to get the maximum date value allowed for the DateTimePicker control.
MinDate This property is used to get or set the minimum date and time that can be selected in the control.
MinimumDateTime This property is used to set the minimum date value allowed for the DateTimePicker control.
Name This property is used to get or set the name of the control.
ShowUpDown This property is used to get or set a value indicating whether a spin button control (also known as an up-down control) is used to adjust the date/time value.
ShowCheckBox This property is used to get or set a value indicating whether a check box is displayed to the left of the selected date.
Size This property is used to get or set the height and width of the control.
Visible This property is used to get or set a value indicating whether the control and all its child controls are displayed.
Value This property is used to get or set the date/time value assigned to the control.
Width This property is used to get or set the width of the control.

Article Tags :
C#