Notifications
Clear all

[Closed] Pressing Enter Key in NumericUpDown

 PEN

So there has been an on going issue trying to detect when the Enter key is pressed when using a NumericUpDown control. The key events don’t catch when Enter is pressed. There are some long winded solutions to this but I wanted something simpler.

Turns out I found a solution. I added a keyUp event to the parent control. There is nothing in the function for it however. Once that has been done the NumericUpDown keyUp event catches the Enter key being pressed and only works when the NumbericUpDown has focus.

5 Replies

Probably about two years from now I’ll run into the same problem, do a search on these forums, and find this post. So on behalf of the future me, thanks.

 PEN

Thank you from my current self to my past self.

there is a well-known test of good implementation of catching Enter pressed/released event for a NumericUpDown control:

if when you press Enter key in edit text area of control the Beep sounds, the event doesn’t work right. if there is no Beep sound – the event works right. (of course in both cases the keypress event must be fired)

BEEP makes a difference between implemented and not implemented

could you show it with a simple snippet, please?

I just used the keyUp event itself, which works for me. This is a little input ui item I call pretty often in some of my tools.

Is this the type situation where you are encountering a problem?



rollout testRollout "" width:140 height:24
(
	dotnetcontrol 	nud "System.Windows.Forms.NumericUpDown" pos:[2,2] width:100
	button 			btn_Done 	"OK" 		pos:[105,2]

	function nud_setup  =
	(
		nud.DecimalPlaces=0
		nud.Increment=1
		nud.maximum=9999
		nud.minimum=1
		nud.ReadOnly=false
		nud.value = 10
	)

	function exit_accept = 
	(
		try(DestroyDialog testRollout)catch()
	)

	function exit_escape = 
	(
		try(DestroyDialog testRollout)catch()
	)

	on btn_Done pressed do 
	(
		exit_accept()
	)

	on testRollout open do 
	(
		setfocus nud
	)

	on nud KeyUp s e do 
	(
		if e.KeyCode == e.KeyCode.Enter do ( exit_accept() )
		if e.KeyCode == e.KeyCode.Escape do ( exit_escape() )
	)
)

CreateDialog testRollout lockHeight:false lockWidth:false --style:#()