Friday, 19 June 2009 03:09 by
Bill Henning (Actipro)
In the upcoming release we've added the TimeSpanEditBox control, which is a parts-based editor for the TimeSpan type. Like the other editors, setting it up is quick and painless. In addition, you can embed your own controls right inside it.
Parts
TimeSpanEditBox comes with parts for days, hours, minutes, seconds, milliseconds, ticks (fractions of a second), and the sign (positive or negative). Each part has an associated format specified, which is fully documented in our help file.
Format Strings
One problem with the TimeSpan type is that it does not have native support for any formatting. When we built the parts-based editor for DateTime (and others), we built a parser for the native format strings so that arranging the parts and including literal strings would be intuitive and easy.
To work around this we defined our own format strings that can be used with the TimeSpanEditBox, which are modeled after DateTime's format strings. There are two types of format strings: standard and custom. Standard format strings are defined using a single character and offer the most common layouts. Custom format strings give you full control over the layout, and allow you to quickly embed literal text.
| TimeSpanEditBox using the 'g' standard format string and a custom format string |
You can also pad each parts with preceding zeros, just like with the DateTime formats.
| TimeSpanEditBox using the 'G' standard format string which uses padding (except for Days part) |
Spinning
All the parts have support for the spinner control and the up/down arrow keys. Like the DateTimeEditBox, you can configure how the control behaves with respect to spinning. For example, if the seconds part currently has focus and has a value of 59, then pressing the up arrow can result in three possible values. The first option is to prevent the value from changing (NoWrap). The second option is to wrap to 0, without affecting any other parts (SimpleWrap). Finally, the third option is to wrap to 0, but to also increment the number of minutes (Wrap).
Summary
TimeSpanEditBox has been one of our most requested parts-based editors and we hope you enjoy it!