The DateTimePicker control in the .NetCF v2 doesn't implement DropDown and CloseUp events which could be really helpful whe dealing with the picker. It doesn't mean that these events or messages are not available in the native counterpart. Win CE SDK docs show the presence of the DTN_CLOSEUP and DTN_DROPDOWN notification messages. It means that they are sent by the DateTime picker to its parent. So, I pulled the NativeWindow class to whip up the DateTimePickerEntender class that suclasses the form, catches the messages and raises the events to the client:
public class DateTimePickerExtender : NativeWindow
{
public event System.EventHandler CloseUp;
public event System.EventHandler DropDown;
private IntPtr handle;
public DateTimePickerExtender(IntPtr handle)
{
this.handle = handle;
// Subclass the window
this.AssignHandle(handle);
}
protected override void WndProc(ref Message m)
{
// Check for notification messages
if (m.Msg == WM_NOTIFY)
{
NMHDR nmhdr = new NMHDR();
Marshal.PtrToStructure(m.LParam, nmhdr);
switch (nmhdr.code)
{
case DTN_DROPDOWN:
// Raise the event
if (DropDown != null)
DropDown(this, new EventArgs());
break;
case DTN_CLOSEUP:
// Raise the event
if (CloseUp != null)
CloseUp(this, new EventArgs());
break;
}
}
base.WndProc(ref m);
}
#region P/Invoke declarations
private const int WM_NOTIFY = 0x004E;
private const int DTN_FIRST = -760;
private const int DTN_DROPDOWN = (DTN_FIRST + 6);
private const int DTN_CLOSEUP = (DTN_FIRST + 7);
private class NMHDR
{
public IntPtr hwndFrom = IntPtr.Zero;
public uint idFrom = 0;
public int code = 0; //uint
}
#endregion
}
Drop the DateTimePicker controls on the form, create and instance of the DateTimePickerExtender and hook up into the events:
DateTimePickerExtender dtEntender;
public Form1()
{
InitializeComponent();
dtEntender = new DateTimePickerExtender(this.Handle);
dtEntender.CloseUp += new EventHandler(dtEntender_CloseUp);
dtEntender.DropDown += new EventHandler(dtEntender_DropDown);
}
void dtEntender_DropDown(object sender, EventArgs e)
{
Console.WriteLine("DropDown event");
}
void dtEntender_CloseUp(object sender, EventArgs e)
{
Console.WriteLine("CloseUp event");
}