DateTimePicker Control in C#

In this article, we will learn how to use datetime picker in windows form in C#.

Let's create windows form.

Step 1
In Visual Studio select "File" = > "New" = > "Project..." then select C# Windows Forms Application then click Ok.

create windows form

Step 2
Let's create Datetimepicker then you go "View" = > select "ToolBox" (Crtl+Alt+X) = > then select "All Windows Forms" = > Choose "dateTimePicker".

  1. First of all, we'll know about the "dateTimePicker".

    DateTimePicker enables to use DateTime and calendar details to the user. We'll discuss properties and functions and events of DateTime picker write down.

    "CalendarFont" Enables what font style use the dateTimePicker Calender.

    dateTimePicker1.CalendarFont = new Font("Arial", 12.0F, FontStyle.Bold);

    "CalendarForeColor" Specifies what font color user to choose.

    dateTimePicker1.CalendarForeColor = Color.Red;

    "CalendarMonthBackground" changes the background color of calender month.

    dateTimePicker1.CalendarMonthBackground = Color.Green;

    "CalendarTitleBackColor" changes the background color of calender title.

    dateTimePicker1.CalendarTitleBackColor = Color.Blue;

    "CalendarTitleForeColor" changes the font color of calender title.

    dateTimePicker1.CalendarTitleForeColor = Color.Blue;

    "CalendarTrailingForeColor" changes the font color of calender trailing fore color.

    dateTimePicker1.CalendarTrailingForeColor = Color.Blue;

    "Cursor" changes cursor style of the user.

    dateTimePicker1.Cursor = Cursors.Hand;

    "DropDownAlign" changes the alignment of the dropdown of calender element.

    dateTimePicker1.DropDownAlign = LeftRightAlignment.Right;

    "Font" changes the style of the text of dateTimePicker box.

    dateTimePicker1.Font = new Font("arial",12.0F, FontStyle.Bold);

    "Hide()" hides the dateTimePicker box.


    "MaxDate" set the maximum date and time of dateTimePicker.

    dateTimePicker1.MaxDate = new DateTime(2000, 02, 2);

    "MinDate" set the minimum date and time of dateTimePicker.

    dateTimePicker1.MinDate = new DateTime(2021, 02, 2);

    "Show()" displays the dateTimePicker.


    "ShowCheckBox" whether a checkbox is displayed to the left of the selected date.

    dateTimePicker1.ShowCheckBox = true;

    "ShowUpDown" gets or sets a value indicating whether a spin button control is used to adjust the date/time value.

    dateTimePicker1.ShowUpDown = true;

    "Value" gets or sets the value date/time of the dateTimePicker.

    dateTimePicker1.Value = new DateTime(2022, 10, 10);

    "Visible" changes the visibility of dateTimePicker.

    dateTimePicker1.Visible = true;

Write a comment

Name Email Message