Articles in this section
Category / Section

How to enforce WinForms DateTimePicker (DateTimePickerAdv) to react on Home and End keys which is a default behavior of .Net DateTimePicker?

1 min read

Behavior of .NET DateTimePicker

We need to override the ProcessCmdKey as illustrated below:

C#

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if(keyData == Keys.Home )
    {
       this.Value = new DateTime(1753,05,31);
    }
    else if(keyData == Keys.End)
    {
       this.Value = new DateTime(2005,05,31);
    }
    return base.ProcessCmdKey(ref msg,keyData);
}

 

VB

Protected Overloads Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
   If keyData = Keys.Home Then
       Me.Value = New DateTime(1753, 5, 31)
   ElseIf keyData = Keys.End Then
       Me.Value = New DateTime(2005, 5, 31)
   End If
   Return MyBase.ProcessCmdKey(msg, keyData)
End Function

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied