| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
How to: Display Time with the DateTimePicker Control |
03/30/2017 |
.net-framework |
|
article |
|
|
0c1c8b40-1b50-4301-a90c-39516775ccb1 |
11 |
dotnet-bot |
dotnetcontent |
wpickett |
How to: Display Time with the DateTimePicker Control
If you want your application to enable users to select a date and time, and to display that date and time in the specified format, use the xref:System.Windows.Forms.DateTimePicker control. The following procedure shows how to use the xref:System.Windows.Forms.DateTimePicker control to display the time.
To display the time with the DateTimePicker control
-
Set the xref:System.Windows.Forms.DateTimePicker.Format%2A property to xref:System.Windows.Forms.DateTimePickerFormat.Time
[!code-csharpSystem.Windows.Forms.DateTimePickerTimeOnly#2] [!code-vbSystem.Windows.Forms.DateTimePickerTimeOnly#2]
-
Set the xref:System.Windows.Forms.DateTimePicker.ShowUpDown%2A property for the xref:System.Windows.Forms.DateTimePicker to
true.[!code-csharpSystem.Windows.Forms.DateTimePickerTimeOnly#3] [!code-vbSystem.Windows.Forms.DateTimePickerTimeOnly#3]
Example
The following code sample shows how to create a xref:System.Windows.Forms.DateTimePicker that enables users to choose a time only.
[!code-csharpSystem.Windows.Forms.DateTimePickerTimeOnly#1] [!code-vbSystem.Windows.Forms.DateTimePickerTimeOnly#1]
Compiling the Code
This example requires:
- References to the System, System.Data, System.Drawing and System.Windows.Forms assemblies.
For information about building this example from the command line for [!INCLUDEvbprvb] or [!INCLUDEcsprcs], see Building from the Command Line or Command-line Building With csc.exe. You can also build this example in [!INCLUDEvsprvs] by pasting the code into a new project. Also see How to: Compile and Run a Complete Windows Forms Code Example Using Visual Studio.