.NET WinForms 的时间选择器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1046268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Time only pickers for .NET WinForms?
提问by Dana Holt
There are tons of good date pickers out there for Windows forms, but I have yet to find any good time only pickers.
有大量适用于 Windows 表单的好的日期选择器,但我还没有找到任何仅适用于时间的选择器。
Any suggestions?
有什么建议?
EDIT
编辑
I guess I should be more clear. I am talking about a nicer looking time picker. We use a commercial control suite, and the default time picker looks out of place because it is so plain.
我想我应该更清楚。我说的是一个更好看的时间选择器。我们使用商业控制套件,默认时间选择器看起来不合适,因为它太简单了。
回答by Michael Petrotta
You mean, as opposed to the standard Winforms DateTimePicker?
你的意思是,相对于标准的 Winforms DateTimePicker?
this.dateTimePicker1.CustomFormat = "hh:mm tt";
this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dateTimePicker1.ShowUpDown = true;
...
...
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
MessageBox.Show(dateTimePicker1.Value.TimeOfDay.ToString());
}
回答by blu
DatePicker has a property Format that can be set to Time. Be sure to set ShowUpDown to True.
DatePicker 有一个属性 Format,可以设置为 Time。确保将 ShowUpDown 设置为 True。
Infragistics is pretty popular for Winforms and has the option for its DateTimePicker.
Infragistics 在 Winforms 中非常流行,并且可以选择 DateTimePicker。
... setting the MaskInput to {time} should get the behavior you are looking for. If you only set the FormatString property, the the time will display only when the control is in edit mode (when the cursor is in the control).
...将 MaskInput 设置为 {time} 应该会得到您正在寻找的行为。如果只设置了 FormatString 属性,则仅当控件处于编辑模式时(光标在控件中时)才会显示时间。
回答by PrimeDime
Just to elaborate on Michael Petrotta'sresponse the code
只是为了详细说明Michael Petrotta 的回应代码
this.dateTimePicker1.CustomFormat = "hh:mm";
is for the 12 hour format, where as the code below is for the 24 hr format
适用于 12 小时制,以下代码适用于 24 小时制
this.dateTimePicker1.CustomFormat = "HH:mm";
回答by sujith
- Add a DateTimePicker control
- Set the property 'Format' to 'Time'
- Set the property 'Custom Format' to 'hh:mm:ss'
- Set the property 'ShowUpDown' to 'True'
- 添加 DateTimePicker 控件
- 将属性“格式”设置为“时间”
- 将属性“自定义格式”设置为“hh:mm:ss”
- 将属性“ShowUpDown”设置为“True”
That's it
就是这样
回答by Loathing
Here is a link to an open source time-picker on sourceforge: https://sourceforge.net/projects/time-picker/
这是 sourceforge 上开源时间选择器的链接:https://sourceforge.net/projects/time-picker/
回答by Kataku
Has been years of this thread but i modified the open source time-picker on sourceforge: https://sourceforge.net/projects/time-picker/to make a dll, just drag from explorer and drop to toolbox and you are ready to go
这个线程已经多年了,但我修改了 sourceforge 上的开源时间选择器:https://sourceforge.net/projects/time-picker/ 来制作一个 dll,只需从资源管理器拖放到工具箱,你就准备好了走
visual studio solution: https://drive.google.com/file/d/1rfV8CXoyUxPuOHQK9dYcZj5WSCSF5gIz/view?usp=sharing
视觉工作室解决方案:https: //drive.google.com/file/d/1rfV8CXoyUxPuOHQK9dYcZj5WSCSF5gIz/view?usp=sharing
on debug folder is the dll
调试文件夹上是 dll


