Page 1 of 1

GUI ComboBox - Activate a selection at start

Posted: 15 Mar 2020, 11:22
by Albireo
The following AHK test program, has a GUI ComboBox.
Depending on what is in the GUI Combobox, a result appears to the right of it.

Code: Select all

#SingleInstance force
#Persistent

SelectVal := "123|456||789"

Gui 1: Font, s16 Normal, Arial
Gui 1: Add, ComboBox, w90 h150 vChoice gCheckChoice, %SelectVal%

Gui 1: Font, cPurple s16 Bold, Arial
Gui 1: Add, Text, xp+100 yp+2 w130 h20 vChoiceText hidden

; Gui 1: Add, Button, xm y+30 gValueCheck, OK!

; Gui +alwaysOntop
Gui 1: Show, x100 y100 w300 h150, %A_ScriptName%
Return

CheckChoice:
	Gui 1: Submit, NoHide

	GuiControl 1: Show, ChoiceText
	If (Choice = 123)
	{	Result = Green
		Goto Next
	}
	If (Choice = 456)
	{	Result = Blue
		Goto Next
	}
	If (Choice = 789)
	{	Result = Red
		Goto Next
	}
	Result := "Undefined"
	
	Next:
	Gui 1: Font, c%Result% s16 Bold, Arial
	GuiControl 1: Text, ChoiceText, %Result%
Return
There are two things that not work as desired, in this example .:
1)
In the example I have set 456 as default.
The 456 is selected when the program starts, but I don't get the result "Blue"
Is it possible to see the results even when the program starts?
How?

2)
I tried to change the color on the text, depending on the result - but I failed.
Is it difficult to solve?
How to do it?

Re: GUI ComboBox - Activate a selection at start  Topic is solved

Posted: 15 Mar 2020, 11:40
by Odlanir

Code: Select all

SelectVal := "123|456||789"

Gui 1: Font, s16 Normal, Arial
Gui 1: Add, ComboBox, w90 h150 vChoice gCheckChoice, %SelectVal%

Gui 1: Font, cPurple s16 Bold, Arial
Gui 1: Add, Text, xp+100 yp+2 w130 h20 vChoiceText -hidden

; Gui 1: Add, Button, xm y+30 gValueCheck, OK!

; Gui +alwaysOntop
Gui 1: Show, x100 y100 w300 h150, %A_ScriptName%
gosub CheckChoice
Return

CheckChoice:
	Gui 1: Submit, NoHide
	If (Choice = 123) {
      Result = Green
	} else If (Choice = 456) {
      Result = Blue
	} else If (Choice = 789) {
      Result = Red
	}
	GuiControl 1: +c%Result%, ChoiceText
	GuiControl 1: , ChoiceText, %Result%
Return

Re: GUI ComboBox - Activate a selection at start

Posted: 15 Mar 2020, 13:07
by Albireo
Thank you! :bravo: