Jump to content
Sign in to follow this  
litlmike

GUICtrlSetOnEvent() behavior with ComboBox

Recommended Posts

litlmike

The current behavior of GUI ComboBoxes to activate GUICtrlSetOnEvent() only occur when the user selects an item from the ComboBox. Is there a way to activate GUICtrlSetOnEvent() to behave like an inputbox, where anytime the user presses {TAB} or {ENTER} it activates GUICtrlSetOnEvent()?

Or am I forced to Add another button that takes care of this?

Code below for the script I am working on, just click an 'Add' button to get a ComboBox to appear. Thanks.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.12.0
 Author:         litlmike

 Script Function:
    AutoIt script.

#ce ----------------------------------------------------------------------------



#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Left=20
Global $Top=20
Global $GuiCtrlCount=0
Global $LastControlID

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### 
$Form2 = GUICreate("Proposal Creator v2", 498, 402, 321, 254)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents")

;~ $GroupBox1 = GUICtrlCreateGroup("Add Proposal Items", 8, 5, 265, 355, $BS_CENTER)
;~ GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("", 280, 10, 95, 110)
$ButtonAddSF = GUICtrlCreateButton("Add SF", 290, 25, 75, 25, 0)
GUICtrlSetOnEvent(-1, "AddStuff")
$ButtonAddCIS = GUICtrlCreateButton("Add CIS", 290, 55, 75, 25, 0)
GUICtrlSetOnEvent(-1, "AddStuff")
$ButtonAddFA = GUICtrlCreateButton("Add FA", 290, 85, 75, 25, 0)
GUICtrlSetOnEvent(-1, "AddStuff")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 280, 120, 95, 50)
$ButtonDelSF = GUICtrlCreateButton("Remove Last", 290, 135, 75, 25)
GUICtrlSetOnEvent(-1, "RemoveStuff")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("", 280, 170, 95, 110)
$ButtonOK = GUICtrlCreateButton("OK", 290, 185, 75, 25)
GUICtrlSetOnEvent(-1, "AddStuff")
$ButtonCancel = GUICtrlCreateButton("Cancel", 290, 215, 75, 25)
GUICtrlSetOnEvent(-1, "SpecialEvents")
$ButtonDone = GUICtrlCreateButton("Done", 290, 245, 75, 25)
GUICtrlSetOnEvent(-1, "SpecialEvents")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("", 385, 10, 105, 110)
$InputTotalPrice = GUICtrlCreateInput("Total Price", 395, 85, 85, 21)
GUICtrlSetOnEvent(-1, "ReductionValue")
$InputReduction = GUICtrlCreateInput("Reduction", 395, 55, 85, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
$InputTotalValue = GUICtrlCreateInput("Total Value", 395, 25, 85, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Funcs;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func AddStuff()
;~  MsgBox(0, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
    Select
        Case @GUI_CtrlId = 4
            AddComboBox ("1497", $Left, $Top)
            $Top+= 30
        Case @GUI_CtrlId = 5
            AddComboBox ("597", $Left, $Top)
            $Top+= 30
        Case @GUI_CtrlId = 6
            AddComboBox ("1132", $Left, $Top)
            $Top+= 30
    EndSelect
EndFunc   ;==>AddStuff

;Remove Box
;Need Last ControlID to Remove
Func RemoveStuff()
    Select
        Case @GUI_CtrlId = 9
            RemoveComboBox ()
            $Top-= 30
    EndSelect
EndFunc   ;==>RemoveStuff

Func AddComboBox ($Text, $X, $Y) ;Add ComboBox to Gui
    Assign ("GuiCtrl" & $GuiCtrlCount, GUICtrlCreateCombo ( $Text, $X, $Y, 150))
    $LastControlID = Eval("GuiCtrl" & $GuiCtrlCount)
    GUICtrlSetOnEvent($LastControlID, "Action")
    AddTValue(GUICtrlRead ($LastControlID))
    ReductionValue()
EndFunc   ;==>AddComboBox

Func RemoveComboBox () ;Remove the Last GUI Ctrl Created
    MinusTValue()
    ReductionValue()
    GUICtrlDelete ($LastControlID)
    $LastControlID-=1 ;Subtract one since the last Ctrl was removed
EndFunc   ;==>RemoveComboBox

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
    EndSelect

EndFunc   ;==>SpecialEvents

Func AddTValue($Price) ;Add To $InputTotalValue
    $CurrentValue = Number(GuiCtrlRead($InputTotalValue)) ;Make Num since GuiCtrlRead is not a Num
    $NewPrice = $CurrentValue + $Price
    GUICtrlSetData ($InputTotalValue, $NewPrice)
EndFunc   ;==>AddTValue

Func MinusTValue() ;Subtract To $InputTotalValue
    $CurrentValue = Number(GuiCtrlRead($InputTotalValue)) ;Make Num since GuiCtrlRead is not a Num
    ConsoleWrite ("$CurrentValue= " & $CurrentValue & @CR)
    $NewPrice = $CurrentValue - GUICtrlRead($LastControlID)
    ConsoleWrite ("$NewPrice= " & $NewPrice & @CR)
    GUICtrlSetData ($InputTotalValue, $NewPrice)
EndFunc   ;==>AddTValue


Func ReductionValue()
    $Value = GuiCtrlRead( $InputTotalValue)
    $FinalPrice = GuiCtrlRead( $InputTotalPrice)
    $Reduction = $Value - $FinalPrice
    GUICtrlSetData ($InputReduction, $Reduction)
EndFunc

Func Action()
    MsgBox(0, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;End of Funcs;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Share this post


Link to post
Share on other sites
Valuater

HotKeySet()...???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
litlmike

HotKeySet()...???

8)

Ha! I actually didn't mean to be so literal as to using {Tab} and {Enter}, but I get your point. The limitation I see here is that a user cannot 'click-out' of the ComboBox either. Meaning, for an Input Ctrl, the user can {Tab}, {Enter}, or click somewhere and the event is activated. This is my hopes for the ComboBox.

Is there a work around to this, or should I just make a button to do it?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.