Reputation: 23187
How can I make it so if you press a number while selecting a DateTimePicker, it won't modify the value?
Currently, I have an onKeyDown to catch all numbers, and set e.Handled = true, but that still doesn't seem to override it.
Thanks!
Upvotes: 0
Views: 1283
Reputation: 81610
Try overriding the OnKeyPress event instead:
protected override void OnKeyPress(KeyPressEventArgs e) {
e.Handled = true;
base.OnKeyPress(e);
}
or if just using the current DateTimePicker without creating your own control:
private void dateTimePicker1_KeyPress(object sender, KeyPressEventArgs e) {
e.Handled = true;
}
The arrow keys should still work.
Upvotes: 1