Articles in this section
Category / Section

How to listen to the key events of WinForms DateTimePicker (DateTimePickerAdv) when the user is typing a new date via the keyboard?

1 min read

Changing the date by using keyboard

The datetimepickerAdv derives from Gradient Panel which in turn derives from the .NET framework panel which does not expose the key events, so you would need to cast the datetimepickerAdv to a control to listen to the key events

C#

private void Form1_Load(object sender, System.EventArgs e)
{
   ((Control)this.dateTimePickerAdv1).KeyUp +=new KeyEventHandler(Form1_KeyUp);
}

 

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    CType(Me.dateTimePickerAdv1, Control).KeyUp += New KeyEventHandler(Form1_KeyUp)
End Sub

 

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