Search code examples
c#winformscalendarpopupdatetimepicker

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#.


Solution

  • 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
    }