Jump to content

creating an array of control


 Share

Recommended Posts

I would like to know how to create an array of combobox control and how to get the index of the control which is got focused now. Please help.

Try this:

$GUI = GUICreate("TEST",110,300)
Dim $CONTROL[7]
For $INDEX = 1 To 6
    $CONTROL[$INDEX] = GUICtrlCreateCombo("CONTROL" & $INDEX,5,$INDEX*50-30,100,20)
Next
GUISetState()

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then Exit
    TrayTip("TEST",ControlGetFocus("TEST"),1)
    Sleep(30)
WEnd

When the words fail... music speaks.

Link to comment
Share on other sites

And another example.

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $msg, $hGui, $Combo[3]
    $hGui = GUICreate("My GUI combo")  ; will create a dialog box that when displayed is centered
    for $n = 0 to UBound($Combo) - 1
    $Combo[$n] = GUICtrlCreateCombo("item1", 10+($n*110), 10, 105) ; create first item
    GUICtrlSetData(-1, "item2|item3", "item3") ; add other item snd set a new default
    next
    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        switch $msg
            case $GUI_EVENT_CLOSE
                ExitLoop
            case $Combo[0]
                MsgBox(0,"",GUICtrlRead($Combo[0]) & " of 1st Combo Box Pressed",0,$hGui)
            case $Combo[1]
                MsgBox(0,"",GUICtrlRead($Combo[1]) & " of 2nd Combo Box Pressed",0,$hGui)
            case $Combo[2]
                MsgBox(0,"",GUICtrlRead($Combo[2]) & " of 3rd Combo Box Pressed",0,$hGui)
        EndSwitch
    WEnd
EndFunc   ;==>Example
Link to comment
Share on other sites

More examples :P

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

Opt("GuiOnEventMode", 1)

Global $aCombo[3]
Dim $sY = 10

$hGUI = GUICreate("Test GUI", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

For $i = 0 To UBound($aCombo) - 1
    $aCombo[$i] = GUICtrlCreateCombo("", 50, $sY, 100, 20)
    GUICtrlSetData(-1, "Item 1|Item 2|Item 3", "Item 1")
    GUICtrlSetOnEvent(-1, "_GetCurSel")
    $sY += 30
Next

GUISetState()

While 1
    Sleep(100)
WEnd

Func _GetCurSel()
    MsgBox(0, "Info", StringFormat("Current selected item: \nID: %s\nItem text: %s\nItem index: %s", _
                                    @GUI_CtrlId, GUICtrlRead(@GUI_CtrlId), GUICtrlSendMsg(@GUI_CtrlId, $CB_GETCURSEL, 0, 0)))
EndFunc

Func _Exit()
    GUIDelete($hGUI)
    Exit
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...