ValueChanged Whenever the user changes the DateTime, this event handler is executed. The window's title shows the DateTime that was selected.
public partial class Form1 : Form
private void Form1_Load(object sender, EventArgs e)
// Initialize picker to yesterday.
DateTime result = DateTime.Today.Subtract(TimeSpan.FromDays(1));
dateTimePicker1.Value = result;
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
// Set title bar to selected date.
DateTime result = dateTimePicker1.Value;
this.Text = result.ToString();
ShowCheckBox. The ShowCheckBox property changes the DateTimePicker to display a check box on the left side. The user can enable or disable the DateTimePicker this way.
Tip To see if the check box is checked, use the Checked property on the DateTimePicker.
ShowUpDown. The ShowUpDown property changes the DateTimePicker such that it displays an up and down arrow box on the right side instead of the drop-down menu.
Tip It is possibly a good idea to set ShowUpDown to True when the DateTime will only need to be changed up or down by a couple units.
Summary. The DateTimePicker control can be used with the Value property and ValueChanged event handler. We can change the UI with ShowCheckBox and ShowUpDown.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Sep 29, 2022 (edit).