using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text.RegularExpressions;
namespace WinUI
{
/// <summary>
/// 用于处理DBNull问题的DateTimePicker
/// </summary>
public class MDateTimePicker :DateTimePicker
{
public object Value
{
get
{
return base.Value;
}
set
{
try
{
DateTime dt=Convert.ToDateTime(value);
base.Value = dt;
}
catch (Exception ex)
{
base.Value = MaxDate;
;
}
}
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
if (Convert.ToDateTime(Value) == MaxDate)
{
Format = DateTimePickerFormat.Custom;
CustomFormat = " ";
}
else
{
Format = DateTimePickerFormat.Long;
}
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
onEdit();
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.KeyCode == Keys.Delete)
{
this.Value = MaxDate;
}
else
{
onEdit();
}
}
private void onEdit()
{
Format = DateTimePickerFormat.Long;
Value = DateTime.Now;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text.RegularExpressions;
namespace WinUI
{
/// <summary>
/// 用于处理DBNull问题的DateTimePicker
/// </summary>
public class MDateTimePicker :DateTimePicker
{
public object Value
{
get
{
return base.Value;
}
set
{
try
{
DateTime dt=Convert.ToDateTime(value);
base.Value = dt;
}
catch (Exception ex)
{
base.Value = MaxDate;
;
}
}
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
if (Convert.ToDateTime(Value) == MaxDate)
{
Format = DateTimePickerFormat.Custom;
CustomFormat = " ";
}
else
{
Format = DateTimePickerFormat.Long;
}
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
onEdit();
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.KeyCode == Keys.Delete)
{
this.Value = MaxDate;
}
else
{
onEdit();
}
}
private void onEdit()
{
Format = DateTimePickerFormat.Long;
Value = DateTime.Now;
}
}
}