views:

131

answers:

5

Hi,

Does anyone know of a good way to have a user enter an amount of time (hours and minutes) using winforms controls? At the moment I have two numeric up downs, one for time and one for minutes that I then parse to create a timespan. The only other idea I have is a text box that a user can enter a "00:00" time in, and validate the input. Both of these ways seem a bit bad (in UI terms) though.

Any ideas?

Thanks

+1  A: 

I normally just use the DateTimePicker control. I select the custom format option and set it to HH:mm and set the ShowUpDown option to true.

Another thing that comes to my mind is to stablish (lets say) minute as your time unit then ask the user for a specific quantity in a textbox.... and add labels telling to enter amount of time in minutes....

Luiscencio
+5  A: 

You can use a MaskedTextBox. This will allow you to have an input box with a format based on the mask you choose (e.g. __:__). This would be useful in the event that a time amount may be above 24 hours (which a DateTimePicker control wouldn't allow you to enter).

Andy E
this worked brilliantly, cheers
Ben
+7  A: 

Entering times is never an easy thing to represent in a UI. Take a look at two things in Windows where times are entered:

  1. Adding a new scheduled task: alt text
  2. Changing the system time: alt text

Both of these use a custom text box type control where you can type a value, or use the up/down control to change the value. Those are probably the best compromise.

You can achieve this yourself by using the built-in DateTimePicker control, and then changing the CustomFormat property to match the format you want (ie. HH:mm for you example of hours and minutes). The ShowUpDown property can also be used to optionally display the spin button control as in the pictures above.

adrianbanks
pretty version of my answer XD
Luiscencio
A: 

Use the clock method 00:00 and put little arrow buttons above and below the hours and minutes section so they can click to increment/decrement, plus they can type it in, just like the vote button on the left.

Marcus Adams
A: 

If you're concerned mainly about usability, and wanting to create a timespan, why not just use 2 drop down lists? 1 for hours, 1 for minutes. Very straightforward and little room for error from the user

David Archer
A drop down list with 60 items in it is not very usable.
adrianbanks
well it could have 15 minute intervals, with a link button saying something like "more minutes?", but still, its an ordered list, so I would argue that its fine
David Archer