views:

361

answers:

4

I am building a form with winforms - and should add a view and editable time span value. Which controls works best for this ?

A normal edit control shows the value correctly -> but it's not really nice for changing values

the normal date time picker doesn't work

the masked edit control doesn't have got any standard mask for this

Does anybody have a good idea for a control for this task ?

+1  A: 

Use a normal textbox, coupled with an error provider control that checks the value using TimeSpan.TryParse() and a tooltip for suggesting what kind of data you're expecting.

If you want, you can combine all that into a single custom control, as well.

Joel Coehoorn
+2  A: 

I built one that had a TextBox coupled with a ComboBox to choose the units. The user control had range settings (value +-) and (time units). Based on the units picked, the text box was ranged checked - e.g., 1-7 days might be valid but if units were minutes, 1-60 minutes might be better.

I've done combinations of two ComboBoxes a NumericUpDown as well.

If you need time spans that are things like 3 days 4 hours 6 minutes, I'd probably opt for a user control with masked text box and range check the parts.

Typically, I opt for the first one, though.

Just my two cents.

itsmatt
the third sounds pretty much like I think the control should work
bernhardrusch
+1  A: 

If your looking for some working code look at the link below.

This blog post provides source code for a WPF User Control for selecting a time span.

mathijsuitmegen
+1  A: 

Use the TimeSpan Helper, which includes a simple Control (that wasn't documented too well when I used it).

Pat