[a137] My problem with radio buttons in tabs

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
HugoM
Posts: 37
Joined: 06 Mar 2018, 14:21

[a137] My problem with radio buttons in tabs

Post by HugoM » 28 Jun 2021, 06:48

Moin,
please see the comments at the start of the code:

Code: Select all

; Test set radio buttons - simplified for tests

; Init: two tabs with 3 Radios each, first checked each
; OK hides it
; Alt + F12 restores it
; Alt+F10 checks radio 2 in tab1, unchecks radio 1
; Alt+F11 checks radio 3 in tab2, unchecks radio 1
;
; My problem: Works in tab1 - radio 1 in tab2 stays also checked
; Btw: same in additional tabs 3, 4, 5 ...

global guiRbs
global rbs1 := Array()
global rbs2 := Array()

SetIniButtons()
{
	global
	
	rbs1.Length := 3
	rbs2.Length := 3
	
	guiRbs := Gui(, "Buttons")
	guiRbs.SetFont("s16" ,"Arial")
	tab := guiRbs.Add("Tab3", "", ["Tab1","Tab2"])
	tab.Move(, , 500, )
	
	tab.UseTab(1)
	rbs1[1] := guiRbs.Add("Radio", "vTab1 Checked", 	"First")
	rbs1[2] := guiRbs.Add("Radio", "								", 	"Second")
	rbs1[3] := guiRbs.Add("Radio", "								", 	"Third")

	tab.UseTab(2)
	rbs2[1] := guiRbs.Add("Radio", "vTab2 Checked", 	"First")
	rbs2[2] := guiRbs.Add("Radio", "								", 	"Second")
	rbs2[3] := guiRbs.Add("Radio", "								", 	"Third")
	
	tab.UseTab()  ;
	okBtn := guiRbs.Add("Button", "section xm default", "&OK")
	okBtn.OnEvent("Click", guiRbsHide)

	guiRbs.OnEvent("Close", guiRbsEnd)

	guiRbs.Show()

	guiRbsHide(this, *)
	{
		if (this is Gui.Control) ; if the Button(or any other Control) was passed in
			this := this.Gui ; get the Gui object, the control belongs to, instead
			this.Hide	
	}

	guiRbsEnd(this, *)
	{
		if (this is Gui.Control) ; if the Button(or any other Control) was passed in
			this := this.Gui ; get the Gui object, the control belongs to, instead
			this.Destroy
	}

}	

SetIniButtons()

!F10::
{
ControlSetChecked(true,  rbs1[2] )
ControlSetChecked(false, rbs1[1] )
}

!F11::
{
ControlSetChecked(true, rbs2[3] )
ControlSetChecked(false,  rbs2[2] )
}

!F12::
{
	guiRbs.Restore()
}
thank you and stay healthy
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [a137] My problem with radio buttons in tabs

Post by swagfag » 28 Jun 2021, 08:24

ur comment says ; Alt+F11 checks radio 3 in tab2, unchecks radio 1
ur code says:

Code: Select all

!F11::
{
ControlSetChecked(true, rbs2[3] )
ControlSetChecked(false,  rbs2[2] )
}
check radio3 in tab2
uncheck radio2 in tab2
HugoM
Posts: 37
Joined: 06 Mar 2018, 14:21

Re: [a137] My problem with radio buttons in tabs

Post by HugoM » 28 Jun 2021, 09:24

Moin and thank you,
yes, sorry, mistake while simplifying. Line 73 should read

Code: Select all

ControlSetChecked(false,  rbs2[1] )
phenomenon stays.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [a137] My problem with radio buttons in tabs

Post by swagfag » 28 Jun 2021, 10:53

i see, yes, ControlSetChecked(false) doesnt uncheck radios on non-active tabsheets. it unchecks stuff by sending it some BM_CLICK messages https://github.com/Lexikos/AutoHotkey_L/blob/7538f26fd92fcfae8749c308e6db3b375d83a10e/source/script_autoit.cpp#L391-L403
it probably doesnt work because of some weird windows interaction
for builtin AHK GUI controls, u can manipulate the control itself instead

Code: Select all

rbs2[3].Value := true
rbs2[1].Value := false
the ControlXXX functions ud usually use when u want to affect an external non-AHK window
HugoM
Posts: 37
Joined: 06 Mar 2018, 14:21

Re: [a137] My problem with radio buttons in tabs

Post by HugoM » 28 Jun 2021, 12:32

Thank you so much.
I see - and probably understand.
With .Value all is fine.
Stay healthy
Post Reply

Return to “Ask for Help (v2)”