GUI ComboBox - Activate a selection at start Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1760
Joined: 16 Oct 2013, 13:53

GUI ComboBox - Activate a selection at start

15 Mar 2020, 11:22

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?
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

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

15 Mar 2020, 11:40

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
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Twisting and 144 guests