960331 - 如何将datetimepicker限制为半小时? [英] 960331 - how to limit datetimepicker to half an hour?

查看:580
本文介绍了960331 - 如何将datetimepicker限制为半小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows应用程序表单中,我需要设置一个时间选择器。我想我可以在System.Windows.Forms.DateTimePicker或Telerik.WinControls.UI.RadDateTimePicker之间进行选择。它不能用于选择日期。它可以在24小时内使用。但是时间应该在半小时内对齐,如00:00,0:00,01:00等等。它不应该是这个。例如。 20:45或05:53是不可接受的。有没有选项可以将这样的控制限制在这些对齐的值上?



我尝试了什么:



它不适用。这不是一个错误。这是我需要的功能。

In a Windows application form, I need to put a time picker. I think I may select between System.Windows.Forms.DateTimePicker or Telerik.WinControls.UI.RadDateTimePicker. It's not to be used to select a date. It's to be used a time in a 24-hours. But the time should be aligned in half-an-hour, like 00:00, 00:30, 01:00 and so on. It should not be out of this. Eg. 20:45 or 05:53 are not acceptable. Is there an option to limit such a control to these aligned values?

What I have tried:

it's not applicable. it's not a bug. it's a feature i need.

推荐答案

请参阅 DateTimePicker类(System.Windows.Forms) [ ^ ]。



[edit]

根据上面链接中的备注设置属性以显示简单的向上时间控件,并将以下代码添加到 ValueChanged 事件处理程序:
See the Remarks section at DateTimePicker Class (System.Windows.Forms)[^].

[edit]
Set the properties according to the remarks in the link above to show a simple up down time control, and add the following code to the ValueChanged event handler:
DateTime dt = dateTimePicker1.Value;
int mins = dt.Minute;
if (mins == 1 || mins == 31)
{
    dt = dt.AddMinutes(29);
    dateTimePicker1.Value = dt;
}



每次按下向上按钮,这将增加30分钟的时间。我留给你添加下按钮的代码和小时的更改。


That will increase the time by 30 minutes every time the up button is pressed. I leave you to add the code for the down button and the change of hour.


这篇关于960331 - 如何将datetimepicker限制为半小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆