DateTime Picker In WinForm How To Pick Time? [duplicate]

落花浮王杯 提交于 2019-11-30 16:26:48

问题


Possible Duplicate:
DateTimePicker: pick both date and time

I'm using a WinForm DateTime picker and it does a fantastic job of choosing dates, but I don't know how to do times. It looks like a time is associated with the value, so maybe there's a way to use this to pick a time?

If there is no built in way to do this, I'll just create another box for the time and modify the DateTime value from the DateTime picker.

Thanks!


回答1:


You can use the built in DateTime picker by adding a custom format string as follows:

DateTimePicker.ShowUpDown = true;
DateTimePicker.CustomFormat = "hh:mm";
DateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;

Enjoy!




回答2:


You can either choose the datepicker to have a "long" date, even only "time" or you can create your custom date.

I always use this format, as it's the most easy one to understand for users (IMHO): yyyy.MM.dd HH:mm

This can be done in the designer the fastest, just change the property.

Or, change it in the program with

YourDatePicker.Format = DateTimePickerFormat.Custom;
YourDatePicker.CustomFormat = "yyyy.MM.dd HH:mm";



回答3:


The DateTimePicker works pretty much like how setting the Windows clock works. If you set the ShowUpDown property to true, it displays a spin control to the right of the DateTimePicker. If you then click on a section of the control, such as the time in hours, and then hit the up or down arrow of the spin control, it will change the time in hours.

Also, if you want to use a custom DateTime format, change the Format property to Custom and set the flags you'd like. For example, MM dddd yyyy HH:mm:ss. For an explanation of all the custom format specifiers, here's the full list of them from MSDN.

Hope that helps.



来源:https://stackoverflow.com/questions/3728116/datetime-picker-in-winform-how-to-pick-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!