Jump to content
Sign in to follow this  
adamski

UpDowns with Up/Down keys

Recommended Posts

adamski

I want to be able to increase/decrease a number in an input box with the arrow up/down keys. The obvious way is to use a updown control - hidden as I don't want it displayed. The problem is that the $UDS_ARROWKEYS style causes the border of the input box to vanish on the side the updown control is.

Is there a way around this or am I going to have to check for focus and then key presses in my own function?

#include <EditConstants.au3>
#include <UpDownConstants.au3>
#include <GUIConstantsEx.au3>

GUICreate("Up Down")

; Inputs
$Input1 = GUICtrlCreateInput ( "0", 10, 10, 100, 20, BitOR($ES_RIGHT,$ES_NUMBER))
$Input2 = GUICtrlCreateInput ( "0", 10, 40, 100, 20, BitOR($ES_RIGHT,$ES_NUMBER))
$Input3 = GUICtrlCreateInput ( "0", 10, 70, 100, 20, BitOR($ES_RIGHT,$ES_NUMBER))
$Input4 = GUICtrlCreateInput ( "0", 10, 100, 100, 20, BitOR($ES_RIGHT,$ES_NUMBER))

; UpDowns
$UpDown1 = GUICtrlCreateUpDown($Input1, BitOR($UDS_ARROWKEYS, $UDS_WRAP))
GUICtrlSetLimit ( $UpDown1, 10 , 0)
GUICtrlSetState ( $UpDown1, $GUI_HIDE )

$UpDown2 = GUICtrlCreateUpDown($Input2, $UDS_ARROWKEYS)
GUICtrlSetLimit ( $UpDown2, 10 , 0)
GUICtrlSetState ( $UpDown2, $GUI_HIDE )

$UpDown3 = GUICtrlCreateUpDown($Input3, BitOR($UDS_ARROWKEYS, $UDS_ALIGNLEFT))
GUICtrlSetLimit ( $UpDown3, 10 , 0)
GUICtrlSetState ( $UpDown3, $GUI_HIDE )

$UpDown4 = GUICtrlCreateUpDown($Input4, $UDS_WRAP)
GUICtrlSetLimit ( $UpDown4, 10 , 0)
GUICtrlSetState ( $UpDown4, $GUI_HIDE )

GUISetState() ; Show GUI

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Share this post


Link to post
Share on other sites
smashly

You could set the Input box to have no border, then use a touch bigger colored label behind it.

#include <EditConstants.au3>
#include <UpDownConstants.au3>
#include <GUIConstantsEx.au3>

GUICreate("Up Down")

GUICtrlCreateLabel("", 9, 9, 88, 16)
GUICtrlSetBkColor(-1, 0x006699)
GUICtrlSetState(-1, $GUI_DISABLE)

$Input1 = GUICtrlCreateInput ( "0", 10, 10, 100, 14, BitOR($ES_RIGHT,$ES_NUMBER), 0)

$UpDown1 = GUICtrlCreateUpDown($Input1, BitOR($UDS_ARROWKEYS, $UDS_WRAP))
GUICtrlSetLimit ( $UpDown1, 10 , 0)
GUICtrlSetState ( $UpDown1, $GUI_HIDE )

GUISetState()
                    
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Share this post


Link to post
Share on other sites
wolf9228

I want to be able to increase/decrease a number in an input box with the arrow up/down keys. The obvious way is to use a updown control - hidden as I don't want it displayed. The problem is that the $UDS_ARROWKEYS style causes the border of the input box to vanish on the side the updown control is.

Is there a way around this or am I going to have to check for focus and then key presses in my own function?

#include <EditConstants.au3>
#include <UpDownConstants.au3>
#include <GUIConstantsEx.au3>

GUICreate("Up Down")

; Inputs
$Input1 = GUICtrlCreateInput ( "0", 10, 10, 100, 20, BitOR($ES_RIGHT,$ES_NUMBER))
$Input2 = GUICtrlCreateInput ( "0", 10, 40, 100, 20, BitOR($ES_RIGHT,$ES_NUMBER))
$Input3 = GUICtrlCreateInput ( "0", 10, 70, 100, 20, BitOR($ES_RIGHT,$ES_NUMBER))
$Input4 = GUICtrlCreateInput ( "0", 10, 100, 100, 20, BitOR($ES_RIGHT,$ES_NUMBER))

; UpDowns
$UpDown1 = GUICtrlCreateUpDown($Input1, BitOR($UDS_ARROWKEYS, $UDS_WRAP))
GUICtrlSetLimit ( $UpDown1, 10 , 0)
GUICtrlSetState ( $UpDown1, $GUI_HIDE )

$UpDown2 = GUICtrlCreateUpDown($Input2, $UDS_ARROWKEYS)
GUICtrlSetLimit ( $UpDown2, 10 , 0)
GUICtrlSetState ( $UpDown2, $GUI_HIDE )

$UpDown3 = GUICtrlCreateUpDown($Input3, BitOR($UDS_ARROWKEYS, $UDS_ALIGNLEFT))
GUICtrlSetLimit ( $UpDown3, 10 , 0)
GUICtrlSetState ( $UpDown3, $GUI_HIDE )

$UpDown4 = GUICtrlCreateUpDown($Input4, $UDS_WRAP)
GUICtrlSetLimit ( $UpDown4, 10 , 0)
GUICtrlSetState ( $UpDown4, $GUI_HIDE )

GUISetState() ; Show GUI

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
adamski

Thanks, that did the trick.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×