Start a new WinForms project, throw a Button and a TextBox on the Form. Run the project. Put the text-edit cursor in the TextBox, and then hit 'Enter: the Button will not be clicked: that's default behavior.
So, why do you think it is that when your focus is on the TextBox and you hit Enter that the Button gets the Click ? It's doing that either because you implemented that at design-time, or run-time (code) ... or, someone implemented that.
There are three things you need to study here to figure out why this is happening in your code:
1. The Form's 'AcceptButton Property
2. The TextBox's 'MultiLine Property
3. The TextBox's 'AcceptsReturn Property
And, now the 'DateTimePicker; try this:
private void dateTimePicker1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Return) button1.PerformClick();
}
You'll notice that this will trigger the Button Click when the DateTimePicker DropDown is "closed," and the control has Focus.
What about the user hitting return while the DTP DropDown is exposed: well ... now, it's time for you to do some study.
I want you to create a test form with a DateTimePicker, and create bound Event Handlers for the 'KeyDown, 'KeyUp, 'PreViewKeyDown, and 'KeyPress Events of the DateTimePicker.
In each of those handlers, write to the Console, or to a TextBox on the Form, the value of the key event ('KeyCode for 'KeyDown, 'KeyUlp, and 'PreViewKeyDown ... 'KeyChar for 'KeyPress).
Also wire-up a handler for the 'ValueChanged Event of the DateTimePicker that will write output to the Console, or to a TextBox.
Now, start the project, and try doing a few things to the DateTimePicker Control:
1. click on its upper area, above the drop-down, and hit return: observe the output
2. cause the Calendar to drop-down, and then with the mouse hovering over a calendar day, hit return.
The idea here is to educate yourself about the behavior of this ... or any other WinForm Control.
Guess what ... they do not behave consistently; these old built-in Controls, valuable as they are, all have their little quirks.
For example, it is common in Windows for hitting Enter while the mouse is over some object to generate a selection of that object, and trigger a selection event; in the Calendar DropDown of the DateTimePicker, you will not get a 'ValueChanged event raised when you hit 'Enter.
Think of yourself as an "astronaut" visitng different planets as you get to know the TextBox, the ListBox, the ListView, the TreeView, etc. :)