如何限制DateTimePicker
仅选择时间?我不知道如何禁用当您按下右侧的按钮时会掉落的日历控件DateTimePicker
。
Answers:
MSDN的摘录:
“以下代码示例显示了如何创建一个DateTimePicker,使用户只能选择一个时间。”
timePicker = new DateTimePicker();
timePicker.Format = DateTimePickerFormat.Time;
timePicker.ShowUpDown = true;
...或者如果您只想显示时间值的一部分,请使用“自定义”:
timePicker = new DateTimePicker();
timePicker.Format = DateTimePickerFormat.Custom;
timePicker.CustomFormat = "HH:mm"; // Only use hours and minutes
timePicker.ShowUpDown = true;
tt
到字符串中。的格式选项全部列表在这里:msdn.microsoft.com/en-us/library/...
最好的方法是这样的:
datetimepicker.Format = DatetimePickerFormat.Custom;
datetimepicker.CustomFormat = "HH:mm tt";
datetimepicker.ShowUpDowm = true;
将以下事件添加到DateTimePicker
Private Sub DateTimePicker1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles DateTimePicker1.KeyPress
e.Handled = True
End Sub