Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms DateTimePicker Dialog?

I need to have a pop-up dialog like the Color Dialog or Save Dialog but for choosing a date from a calendar. The DateTimePicker is what I need, but I don't know how to launch this like a pop-up dialog in C#.

like image 835
James Avatar asked Jan 23 '23 10:01

James


1 Answers

You need to add a DateTimePicker to a form and show the form as a dialog:

var picker = new DateTimePicker();
Form f = new Form();
f.Controls.Add(picker);

var result = f.ShowDialog();
if(result == DialogResult.OK)
{
    //get selected date
}
like image 153
Lee Avatar answered Jan 25 '23 00:01

Lee