Help with Creating and populating a GUI?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nhanderr
Posts: 9
Joined: 21 Jun 2022, 18:19

Help with Creating and populating a GUI?

Post by nhanderr » 27 Jun 2022, 12:24

Hi all,

I was hoping for help in creating and populating a GUI. I don't have much familiarity with this so I was hoping for some assistance in setting this up. Ideally the GUI would look like below:
image.png
image.png (20.56 KiB) Viewed 352 times

The left hand column would populate with names of templates, while the right hand column would populate with the contents of said template depending on which selection was clicked on the left hand column. Hitting select would then paste the template into a textbox.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Help with Creating and populating a GUI?

Post by BoBo » 27 Jun 2022, 12:51

Something to start with, mainly stolen from AHK's help...

Code: Select all

#SingleInstance, Force

Gui, Add, ListView, x10 y10 r20 w300 h300 gMyListView, Name|Size (KB)
Gui, Add, Edit, xp+310 yp wp hp+8 readonly wrap vLB
Loop, %A_ScriptDir%\*.ahk
    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)

LV_ModifyCol()  ; Auto-size each column to fit its contents.
LV_ModifyCol(2, "Integer")  ; For sorting purposes, indicate that column 2 is an integer.

; Display the window and return. The script will be notified whenever the user double clicks a row.
Gui, Show,, Test
return

MyListView:
if (A_GuiEvent = "DoubleClick") {
   GuiControl,, LB,% ""
   LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
   FileRead, content,% RowText
   GuiControl,, LB,% content
   }
return

GuiClose:  ; Indicate that the script should exit automatically when the window is closed.
ExitApp
Double clicking on a row will update the content within the viewer pane. Now it's up to you to add some buttons. Good luck ;)

User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Help with Creating and populating a GUI?

Post by AlphaBravo » 27 Jun 2022, 12:53

here is something to get you started

Code: Select all

oTemplate := {"One":"One Contents", "Two":"Two Contents"}
for template, v in oTemplate
	templates .= template "|"
templates := Trim(templates, "|")						; remove extra "|" at the end
templates := StrReplace(templates, "|", "||",, 1) 		; replace first "|" with "||" ie first item is selected

Gui, add, ListBox, h200 vLB gPopulate, % templates
Gui, add, Edit, x+10 hp w400 vtextbox ReadOnly
Gui, show
gosub, Populate
return

Populate:
Gui, Submit, NoHide
GuiControl, , textbox, % oTemplate[LB]
return

Post Reply

Return to “Ask for Help (v1)”