Mic*_*tta 19
你的意思是,而不是标准的Winforms DateTimePicker?
this.dateTimePicker1.CustomFormat = "hh:mm tt";
this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dateTimePicker1.ShowUpDown = true;
Run Code Online (Sandbox Code Playgroud)
...
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
MessageBox.Show(dateTimePicker1.Value.TimeOfDay.ToString());
}
Run Code Online (Sandbox Code Playgroud)
blu*_*blu 16
DatePicker具有可以设置为Time的属性Format.务必将ShowUpDown设置为True.
Infragistics在Winforms中非常流行,并且可以选择DateTimePicker.
...将MaskInput设置为{time}应该可以获得您正在寻找的行为.如果仅设置FormatString属性,则仅当控件处于编辑模式时(光标位于控件中时)才会显示时间.
来自http://forums.infragistics.com/forums/t/4172.aspx
小智 8
只是详细阐述Michael Petrotta对代码的回应
this.dateTimePicker1.CustomFormat = "hh:mm";
Run Code Online (Sandbox Code Playgroud)
是12小时格式,其中下面的代码是24小时格式
this.dateTimePicker1.CustomFormat = "HH:mm";
Run Code Online (Sandbox Code Playgroud)