Page 1 of 1
GUI. Only show control depending on dropdownlist value?
Posted: 20 Mar 2023, 04:03
by Krd
Hello folks!
How to only show the Datetime control below only of second alternative is choosen from DD-list?
Code: Select all
MyGui := Gui()
Tab := MyGui.Add("Tab3",, ["One","Two"])
Tab.UseTab(1)
MyGui.Add("Text", , "Choose something:")
MyGui.Add("DropDownList", "vAlts", ["Alter1","Alter2 with datetime"])
MyGui.Add("DateTime", "vDate")
Tab.UseTab(2)
MyGui.Add("Text", , "Nothing")
MyGui.Show()
This way I could hide unnecessary controls for minimalistic view for the user.
If there is an "easy" way as I don't want to make it complicated
Thanks in advance!
Re: GUI. Only show control depending on dropdownlist value? Topic is solved
Posted: 20 Mar 2023, 06:01
by Smile_
Code: Select all
#Requires AutoHotkey v2.0.2
#SingleInstance Force
MyGui := Gui()
Tab := MyGui.Add("Tab3",, ["One","Two"])
Tab.UseTab(1)
MyGui.Add("Text", , "Choose something:")
MyGui.Add("DropDownList", "vAlts", ["Alter1","Alter2 with datetime"]).OnEvent('Change', Ctrl_Change)
DT := MyGui.Add("DateTime", "vDate +Hidden")
Tab.UseTab(2)
MyGui.Add("Text", , "Nothing")
MyGui.Show()
Return
Ctrl_Change(GuiCtrlObj, Info) {
If GuiCtrlObj.Value = 2 {
If !DT.Visible {
DT.Visible := True
}
} Else If DT.Visible {
DT.Visible := False
}
}
Re: GUI. Only show control depending on dropdownlist value?
Posted: 20 Mar 2023, 06:45
by Krd
Wow, this will make things much better!
Thank you so much!
Re: GUI. Only show control depending on dropdownlist value?
Posted: 20 Mar 2023, 12:23
by Krd
@Smile_
Code: Select all
Ctrl_Change(GuiCtrlObj, Info) {
If GuiCtrlObj.Value = 2 {
If !DT.Visible {
DT.Visible := True
}
} Else If DT.Visible {
DT.Visible := False
}
}
Just found another use for this code which would make things even better.
If I have 10 variables named Dt1, DT2, DT3...Dt10
How to change it loop through variables, something like the below but that works?
Code: Select all
Ctrl_Change(GuiCtrlObj, Info) {
If GuiCtrlObj.Value = 2 {
If !DT[1-10].Visible {
DT[1-10].Visible := True
}
} Else If DT[1-10].Visible {
DT[1-10].Visible := False
}
}
I want to avoid to make tens lines of variables.
Thanks again
Re: GUI. Only show control depending on dropdownlist value?
Posted: 20 Mar 2023, 17:38
by Smile_
How is this
Code: Select all
#Requires AutoHotkey v2.0.2
#SingleInstance Force
MyGui := Gui()
Tab := MyGui.Add("Tab3",, ["One","Two"])
Tab.UseTab(1)
MyGui.Add("Text", , "Choose something:")
MyGui.Add("DropDownList", "vAlts Choose2", ["Alter1","Alter2 with datetime"]).OnEvent('Change', Ctrl_Change)
DT := []
Loop 10
DT.Push(MyGui.Add("DateTime"))
Tab.UseTab(2)
MyGui.Add("Text", , "Nothing")
MyGui.Show()
Return
Ctrl_Change(GuiCtrlObj, Info) {
If GuiCtrlObj.Value = 2 {
Loop 10 {
If !DT[A_Index].Visible {
DT[A_Index].Visible := True
}
}
} Else {
Loop 10 {
If DT[A_Index].Visible {
DT[A_Index].Visible := False
}
}
}
}
Re: GUI. Only show control depending on dropdownlist value?
Posted: 22 Mar 2023, 12:30
by Krd
Awesome!
I have now used your code with many of my GUIs and things are so much nicer
And I have tried to play with them to know how to use it.
Thank you so much!