我有一点简单的辩证,让用户设置一个“时段”。 用户表示,该区块的起步时间是规定的,然后可以进入一个期限,也可以进入终点区。 例如,他们要么说从8AM开始,到11AM结束,要么从8AM开始,到180分钟。 在此期间,我都有一个文本箱,最后还有一个日期。 日冕物质习惯形式为“hh:mm tt”。 文本框仅作罚款。 关于文本箱的请假活动,我用正确的结束时间更新了日期。
然而,让日子工去工作并不容易。 当休假事件发生时,该日子总价值正确。
Also, I have a requirement to make sure the duration of the time block is at least 15 minutes, so ideally, when the user "Leaves" either control, I can update the other control, and also validate that its at least 15 minutes. (If < 15, I set it to 15).
Ok, time for some Code:
private void SetDuration(int Duration)
{
Duration = Math.Max(15, Duration);
m_TextBoxDuration.Text = Duration.ToString();
m_DateTimePickerEndTime.Value = m_DateTimePickerStartTime.Value.AddMinutes(Duration);
}
private void m_TextBoxDuration_Leave(object sender, EventArgs e)
{
int duration = 0;
int.TryParse(m_TextBoxDuration.Text, out duration);
SetDuration(duration);
}
private void m_DateTimePickerEndTime_Leave(object sender, EventArgs e)
{
SetDuration((int)(m_DateTimePickerEndTime.Value.Subtract(m_DateTimePickerStartTime.Value).TotalMinutes));
}
Here s the difference. Suppose the date time picker has its time set to 07:00 PM. If the user highlights the "07" and types 6 then hits Tab, the Leave event fires before the ValueChanged event. If the user types 06 and then Tab, the events go in reverse order. So I cannot rely on either event to be the final event. I don t want to (can t) update every time I get the ValueChanged event, because then the minimum duration requirement can really mess with the user trying to make edits.
帮助?