Need help to change Value of a GUI Control

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
GamesOfFreak
Posts: 28
Joined: 15 Sep 2020, 03:51
Location: Germany
Contact:

Need help to change Value of a GUI Control

Post by GamesOfFreak » 19 May 2023, 13:17

I have a ComboBox called "mcGiveGenerator.ComboBox.One" and a DropdownList called "mcGiveGenerator.DropDownList.One".

If I select a Value in the Dropdown List Then it should change the Value to a predefined Array List inside of the ComboBox.

How can I do that exactly?

Also I need to mention that the Code below only a part of the Script so don't get confused if some Variables etc. not shown up in the Code.

Code: Select all

mcGiveGenerator := Gui("+LastFound +Owner", "Minecraft Command Kit: Give Command")
mcGiveGenerator.BackColor := 0xF5F5F5
mcGiveGenerator.OnEvent("Size", GuiReSizer)
mcGiveGenerator.Edit := {}
mcGiveGenerator.Picture := {}
mcGiveGenerator.Text := {}
mcGiveGenerator.DropDownList := {}
mcGiveGenerator.UpDown := {}
mcGiveGenerator.ComboBox := {}

mcGiveGenerator.ComboBox.One := mcGiveGenerator.Add("ComboBox", "x35 y15 w370 +Lowercase -Multi vItemSearch", MCItemList)

mcGiveGenerator.Edit.Two := mcGiveGenerator.Add("Edit", "x35 y60 w370 h20 +Lowercase -Multi vEntityTarget")
mcGiveGenerator.Edit.Four := mcGiveGenerator.Add("Edit", "x15 y105 w780 h202 ReadOnly")

mcGiveGenerator.Picture.One := mcGiveGenerator.Add("Picture", "w20 h20 x15 y15", A_ScriptDir "\icons\search.png")
mcGiveGenerator.Picture.Two := mcGiveGenerator.Add("Picture", "w20 h20 x15 y60", A_ScriptDir "\icons\player.png")

mcGiveGenerator.Text.One := mcGiveGenerator.Add("Text", "x475 y18", "Minecraft Version:")
mcGiveGenerator.Text.Two := mcGiveGenerator.Add("Text", "x475 y63", "Give Amount:")

mcGiveGenerator.Edit.Three := mcGiveGenerator.Add("Edit", " x623 y60 w172 +Lowercase +Number -Multi")
mcGiveGenerator.UpDown.One := mcGiveGenerator.Add("UpDown", "vGiveItemAmount Range1-64", "1")

mcGiveGenerator.DropDownList.One := mcGiveGenerator.Add("DropDownList", "x623 y15 w172 vMCVersion", ["Java 1.19+", "Java 1.18", "Java 1.17", "Java 1.16", "Java 1.15", "Java 1.14", "Java 1.13", "Java 1.12"])
mcGiveGenerator.DropDownList.One.Text := "Java 1.19+"

mcGiveGenerator.DropDownList.One.OnEvent("Change", mcGiveGeneratorOnChangeVersion)

mcGiveGenerator.OnEvent("Close", mcGiveGeneratorOnClose)

mcGiveGeneratorOnChangeVersion(*) {
    if mcGiveGenerator.DropDownList.One.Value == "Java 1.12"
        MCItemList := MCItemList112
    else if mcGiveGenerator.DropDownList.One.Value == "Java 1.13"
        MCItemList := MCItemList113
    else if mcGiveGenerator.DropDownList.One.Value == "Java 1.14"
        MCItemList := MCItemList114
    else if mcGiveGenerator.DropDownList.One.Value == "Java 1.15"
        MCItemList := MCItemList115
    else if mcGiveGenerator.DropDownList.One.Value == "Java 1.16"
        MCItemList := MCItemList116
    else if mcGiveGenerator.DropDownList.One.Value == "Java 1.17"
        MCItemList := MCItemList117
    else if mcGiveGenerator.DropDownList.One.Value == "Java 1.18"
        MCItemList := MCItemList118
    else if mcGiveGenerator.DropDownList.One.Value == "Java 1.19"
        MCItemList := MCItemList119
    return
}

mcGiveGeneratorOnClose(*) {
    WinSetEnabled(1, "ahk_id" mcCommandGenerator.Hwnd)
    return
}

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Need help to change Value of a GUI Control

Post by mikeyww » 19 May 2023, 15:49

An example is below.

Code: Select all

#Requires AutoHotkey v2.0
cbMap := Map(
   'a', [1, 2]
 , 'b', [3, 4]
 , 'c', [5, 6]
)
ddlList := []
For item in cbMap
 ddlList.Push(item)
gui1 := Gui(, 'Test'), gui1.SetFont('s10')
gui1.AddDDL('w250', ddlList).OnEvent('Change', ddl_Change)
cb := gui1.AddComboBox('wp')
gui1.Show

ddl_Change(ddl, info) {
 cb.Delete(), cb.Add(cbMap[ddl.Text])
 SoundBeep 1500
}

GamesOfFreak
Posts: 28
Joined: 15 Sep 2020, 03:51
Location: Germany
Contact:

Re: Need help to change Value of a GUI Control

Post by GamesOfFreak » 19 May 2023, 17:25

Thank you for the example!

I had to change your example a bit in my case, but you definitely pointed me in the right direction of what to do.

Post Reply

Return to “Ask for Help (v2)”