Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-display-time-with-the-datetimepicker-control.md
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.6 KiB

title, description, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title description ms.date dev_langs helpviewer_keywords ms.assetid
How to: Display Time with the DateTimePicker Control Learn how to use the Windows Forms DateTimePicker control to enable users to select a date and time, and to display that date and time in the specified format. 03/30/2017
csharp
vb
time [Windows Forms], displaying in DateTimePicker control
examples [Windows Forms], DateTimePicker control
DateTimePicker control [Windows Forms], displaying time
0c1c8b40-1b50-4301-a90c-39516775ccb1

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

  1. 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]

  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.

See also