mikeyww wrote: ↑06 Feb 2023, 10:45
GUI Example for AHK v2
A slightly more advanced example:
Code: Select all
guiMain := Gui(,"Main Gui"), guiMain.Edit := {}
guiMain.Add("Text","w75 Right", "Stuff:")
guiMain.Edit.Stuff := guiMain.Add("Edit", "x100 yp w400")
guiMain.Add("Text","y+20 x10 w75 Right", "Other Stuff:")
guiMain.Edit.Other := guiMain.Add("Edit", "x100 yp w400")
guiMain.Add("Button", "Default y+20 xm+100 w150", "Confirm").OnEvent("Click", guiMain_Button_Click)
guiMain.Add("Button", "xm+300 yp w150", "Clear").OnEvent("Click", guiMain_Button_Click)
guiMain.Show
Esc::ExitApp
guiMain_Button_Click(Button, Info)
{
If (Button.Text = "Confirm")
MsgBox "Stuff: " guiMain.Edit.Stuff.Text "`nOther Stuff: " guiMain.Edit.Other.Text
else
for EditName, EditCtrl in guiMain.Edit.OwnProps()
EditCtrl.Text := ""
}
This is really more about how to organize things for when you get a lot of Gui with lots of controls.
I find it very useful to keep all handles for a particular Gui within the same object that holds the Gui. Also by using an object structure, you can loop easily through controls as shown here when clearing the Edit controls. When you have 20 checkboxes it can really be useful to loop through them.
Also, this shows that every control event does not have to go to a separate function. It can often condense your code considerably to have a fewer number of more generic event handlers.
This is more for others that might google this thread than for
@mikeyww. This just adds a few tricks for those that want to take it a little further.
FG