Time Picker
A time field with a drop-down of spin columns – hours, minutes, seconds and AM/PM – for picking a time of day: an appointment, a delivery slot, a shift start.
Assembly
| Assembly | Binarymission.WinForms.Controls.AdvancedSelectors.dll |
| Root namespace | Binarymission.WinForms.Controls.Selectors |
| Target frameworks | .NET Framework 4.8, .NET 6 / 8 / 10 |
| Depends on | DoubleBufferedControlBase, PopupEditor |
Overview
What it is for
The control shows the time as text, with a button beside it. The button opens a drop-down holding a column for each part of the time, each with an up arrow, the value and a down arrow. The user clicks the arrows, holds them down or turns the mouse wheel over them, and the text follows every change. The drop-down closes when the user clicks elsewhere, and can be resized by its bottom edge.
How to use it
- Set
TimeValueto the starting time and read it back for the picked time. TimeConventionchooses the twelve- or twenty-four-hour clock, andTwelveHoursTimeDisplayFormatorTwentyFourHoursTimeDisplayFormatthe way the text is written.Intervalsets the step of the arrows, andMousePressedValueChangeTriggerSpeedhow fast a held arrow repeats.DropDownViewOpenedtells you when the drop-down opens.
Appearance
The colours of the arrows, the value boxes and the column backgrounds are properties of this control. The
look of the text field, the drop-down button and the drop-down window – fonts, borders, size, resize strip – is
in DropDownHostConfiguration. The drop-down's parts read their settings when it is first created,
so set the appearance before it first opens.
Getting started
A collection-time picker on a booking form, on the twenty-four-hour clock without seconds.
using System;
using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.Selectors.TimeSelectors;
var collectionTime = new TimePickerDropDown
{
Location = new Point(16, 16),
Size = new Size(180, 32),
TimeConvention = TimeConvention.TwentyFourHours,
TwentyFourHoursTimeDisplayFormat = "HH:mm",
SpinnerBackgroundBrushStartColor = Color.SteelBlue,
SpinnerHoverBackgroundBrushStartColor = Color.DodgerBlue,
SpinnerPressedBackgroundBrushStartColor = Color.Navy
};
collectionTime.TimeValue = DateTime.Today.AddHours(9).AddMinutes(30);
collectionTime.DropDownHostConfiguration.PopupCommandVisualNormalBackColor = Color.SteelBlue;
collectionTime.DropDownHostConfiguration.PopupCommandVisualBorderColor = Color.SteelBlue;
collectionTime.DropDownViewOpened += (sender, e) => statusLabel.Text = "Choose a collection time";
bookingForm.Controls.Add(collectionTime);API reference
Binarymission.WinForms.Controls.Selectors.TimeSelectors
class DropDownHostConfiguration | The look and behaviour of a TimePickerDropDown's text field, its drop-down button and the drop-down window: fonts, colours, borders, the drop-down's size and position, and its resize strip. |
interface ITimePickerHost | The settings a time picker's drop-down reads from the control that hosts it: the step and repeat rate of the arrows, the fonts and colours of the columns, and the time itself. |
enum TimeConvention | Specifies the clock a TimePickerDropDown shows and picks times on. |
class TimePickerDropDown | A time field with a drop-down of spin columns - hours, minutes, seconds and AM/PM - for picking a time of day: an appointment, a delivery slot, a shift start. |