views:

272

answers:

2

Hello,

I have a keyUp event in button1 and EnterEvent in button2

When i press button1 and use my up arrow automatically control is navigating to Enter Event of button2 after entering into the KeyUp event of button1

Feels something fishy; Please help !!

A: 

From MSDN

"The Enter event occurs before a control actually receives the focus from a control on the same form."

sounds like its doing the right thing, when you press the up arrow focus is being switched to the next button (Button2) which is causing the Enter event to fire.

Mauro
+1  A: 

Just to be clear, the KeyUp event doesn't refer specifically to the Up key on your keyboard. It is an event that triggers anytime you release any key. The keyboard events are KeyDown (when you push any key down), KeyPress (after KeyDown), and KeyUp (when you let go of the key). If you hold down a key, the KeyDown and KeyPress events trigger repeatedly until you let go, at which point KeyUp fires. (Note: pressing the Enter key on a control that is set as Default or pressing the Esc key on a control that is set as Cancel will NOT trigger any of the Key events for those controls.)

Also, the Enter event doesn't refer to the Enter key, it refers to anytime you enter that control, whether by clicking your mouse into it or moving to it via the keyboard.

In light of all of this, here's what looks to be happening:

You press and release the Up Arrow on your button1, triggering button1's KeyUp event. The focus then moves to button2 (because you pressed the Up arrow key, a navigation key) and triggers the Enter event of button2 (because you just entered button2).

KevenDenen