views:

203

answers:

2

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

A: 

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.

Adam Robinson
That's what I was afraid of, but is there any way to make a dialog?
James
There is no way in win forms other than Form
anishmarokey
@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 call `ShowDialog`. You'll probably also want to set the `FormBorderStyle` to `FixedDialog`.
Adam Robinson
Perfect, thanks!
James
A: 

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
}
Lee
Thanks, this is what I was looking for.
James