WinForms DateTimePicker Dialog?
15,836
Solution 1
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
}
Solution 2
The DateTimePicker
is a Control
, not a Form
. You'll have to create your own Form
and add the control to it; there is not a standard dialog for selecting dates.
Author by
James
Updated on June 04, 2022Comments
-
James over 1 year
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#.
-
James over 13 yearsThat's what I was afraid of, but is there any way to make a dialog?
-
anishMarokey over 13 yearsThere is no way in win forms other than Form
-
Adam Robinson over 13 years@James: Like I said, you'll just need to create another
Form
, add the control (and any properties you'll need; I'd assume you'd need one to get/set the value displayed), then instantiate it and callShowDialog
. You'll probably also want to set theFormBorderStyle
toFixedDialog
.