背景
我们有一个基于 VB.NET 的遗留表单应用程序,目前正在重新开发为基于 c# MVC Web 的应用程序。在进行重新开发时,我需要保持基于表单的应用程序继续运行。在整个应用程序(数百个字段)中,我们使用了一个名为 nullableDateTimePicker ( VBDateTimePicker.ProjectMentor.Windows.Controls.nullableDateTimePicker ) 的控件,因为我们需要一个可以处理 NULL 日期的控件。
问题
此控件多年来一直运行良好,但现在似乎已停止工作,并且当控件具有空值时,从选取器中选择一个日期将不会填充选取器。如果控件有日期,则从选取器中选择时日期将正确更改。肯定有 Windows 更新或其他一些环境变化破坏了控制。
问题
在 CodeProject 源代码的 NullableDateTimePicker.cs 中,我们有以下内容:
protected override void OnValueChanged(EventArgs eventargs) { base.OnValueChanged(eventargs); }
However, this does not appear to update the value when chosen when the controls Value is set to null.来自 codeproject(链接在上方和下方)的演示项目在已打补丁的 Windows 7/Windows 8 机器上表现出相同的损坏行为。
为了方便下载,我还弹出了压缩包here on dropbox .
最佳答案
我会避免重写 WndProc 方法,而只是重写 OnCloseUp 方法:
//protected override void WndProc(ref Message m)
//{
// if (_isNull)
// {
// if (m.Msg == 0x4e) // WM_NOTIFY
// {
// NMHDR nm = (NMHDR)m.GetLParam(typeof(NMHDR));
// if (nm.Code == -746 || nm.Code == -722) // DTN_CLOSEUP || DTN_?
// SetToDateTimeValue();
// }
// }
// base.WndProc(ref m);
//}
protected override void OnCloseUp(EventArgs eventargs) {
if (_isNull) {
SetToDateTimeValue();
}
base.OnCloseUp(eventargs);
}
关于c# - VB.Net VBDateTimePicker (可空日期时间选择器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20844555/