English 中文(简体)
日期 病假/价值 变化的活动
原标题:DateTimePicker Leave / ValueChanged events

我有一点简单的辩证,让用户设置一个“时段”。 用户表示,该区块的起步时间是规定的,然后可以进入一个期限,也可以进入终点区。 例如,他们要么说从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.

帮助?

最佳回答

在离开之前,你首先需要验证控制。 如果你从m_DatetimePickerEndtime到文本箱,你可以这样做。 重点验证所有控制。

private void m_DateTimePickerEndTime_Leave(object sender, EventArgs e)
{    
  this.Focus();      
  SetDuration((int(m_DateTimePickerEndTime.Value.Subtract
          (m_DateTimePickerStartTime.Value).TotalMinutes));    
}

如果您的表态不同,就认为了这一点。 其他休假活动的重点。

问题回答

暂无回答




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签