Visual C#

Windows Control: The Time Picker Control

As described already, the date time picker is two controls in one object. To transform a date time picker into a time picker control, change its Format…

3 min read622 words

Introduction to the Time Picker Control#

As described already, the date time picker is two controls in one object. To transform a date time picker into a time picker control, change its Format property to a Time value:

Although optional, you should (with emphasis) also set the ShowUpDown Boolean property to True. This makes it a true time picker control:

If you do not set the ShowUpDown property to true, the control would display as a combo box and when the user clicks the arrow button, a calendar would come, which does not make sense since the purpose of the control is to deal with time values. Practical Learning: Introducing the Date Picker

  1. Start a new Windows Application named GeorgetownCleaningServices2
  2. Design the form as follows: Control Name Text Additional Properties GroupBox Order Identification Label Customer Name: TextBox txtCustomerName Label Customer Phone: TextBox txtCustomerPhone Label Date Left: DateTimePicker dtpDateLeft Label Time Left: DateTimePicker dtpTimeLeft Format: Time Label Date Expected: DateTimePicker dtpDateExpected Label Time Expected: DateTimePicker dtpTimeExpected Format: Time GroupBox Order Processing Label Item Type Label Unit Price Label Qty Label Sub Total Label Shirts TextBox txtShirtsUnitPrice 1.25 TextAlign: Right TextBox txtShirtsQuantity 0 TextAlign: Right TextBox txtShirtsSubTotal 0.00 TextAlign: Right Label Pants TextBox txtPantsUnitPrice 1.95 TextAlign: Right TextBox txtPantsQuantity TextAlign: Right TextBox txtPantsSubTotal 0.00 TextAlign: Right ComboBox cbxItem1 None Items: None Women Suit Dress Regular Skirt Skirt With Hook Men's Suit 2Pc Men's Suit 3Pc Sweaters Silk Shirt Tie Coat Jacket Swede TextBox txtItem1UnitPrice 0.00 TextAlign: Right TextBox txtItem1Quantity 0 TextAlign: Right TextBox txtItem1SubTotal 0.00 TextAlign: Right ComboBox cbxItem2 None Items: None Women Suit Dress Regular Skirt Skirt With Hook Men's Suit 2Pc Men's Suit 3Pc Sweaters Silk Shirt Tie Coat Jacket Swede TextBox txtItem2UnitPrice 0.00 TextAlign: Right TextBox txtItem2Quantity 0 TextAlign: Right TextBox txtItem2SubTotal 0.00 TextAlign: Right ComboBox cbxItem3 None Items: None Women Suit Dress Regular Skirt Skirt With Hook Men's Suit 2Pc Men's Suit 3Pc Sweaters Silk Shirt Tie Coat Jacket Swede TextBox txtItem3UnitPrice 0.00 TextAlign: Right TextBox txtItem3Quantity 0 TextAlign: Right TextBox txtItem3SubTotal 0.00 TextAlign: Right ComboBox cbxItem4 None Items: None Women Suit Dress Regular Skirt Skirt With Hook Men's Suit 2Pc Men's Suit 3Pc Sweaters Silk Shirt Tie Coat Jacket Swede TextBox txtItem4UnitPrice 0.00 TextAlign: Right TextBox txtItem4Quantity 0 TextAlign: Right TextBox txtItem4SubTotal 0.00 TextAlign: Right GroupBox Order Summary Button btnCalculate Calculate Label Cleaning Total: TextBox txtCleaningTotal 0.00 TextAlign: Right Label Tax Rate: TextBox txtTaxRate 7.75 TextAlign: Right Label % Label Tax Amount: TextBox txtTaxAmount 0.00 TextAlign: Right Label Net Total: TextBox txtNetPrice 0.00 TextAlign: Right Button btnClose Close
  3. Save the form

Using the Time Picker#

The time picker is meant either to only display a time to the user or to both display time and allow the user to specify a time. The control follows the format of the time values set in the regional settings of Control Panel. By default, in US English, the time is divided in four sections that include the hour value, the minute value, the second value, and the AM/PM side. These sections are separated by standard characters that also are specified in the regional settings of Control Panel. To change the time, the user can click a section, such as the hour, the minute, the second, or the AP/PM side, then click one of the arrows of the spin button. The up button increases (only) the value of the selected section while the down button decreases (only) the value of the selected section. The user can also use the arrow keys to change the value of a section. After changing the of the time, even the change occurs for only one section, the control fires a ValueChanged event, which is the default event of the control. Home Copyright © 2008-2009 C# Key Next