How to calculate total height of controls

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

How to calculate total height of controls

Post by m3user » 22 Aug 2023, 05:27

I would like to add a colored bar on the right side of the gui. The height of the bar (progress control) should be the same as a size of all controls on the left.
How to determine the height of the bar automatically, regardless the number of controls and font used? Thanks.

Code: Select all

gui, font, s10
gui, add, edit, w100 vEdit1
gui, add, edit, w100 vEdit2
gui, add, edit, w100 vEdit3
gui, add, button, w50, OK
gui, add, progress, xm+110 ym w30 h110 cSilver, 100
gui, show
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: How to calculate total height of controls

Post by mikeyww » 22 Aug 2023, 06:01

Code: Select all

#Requires AutoHotkey v1.1.33
Gui +HwndhGui
Gui Font, s10
Gui Add, Edit    , w200 vEdit1
Gui Add, Edit    , wp   vEdit2
Gui Add, Edit    , wp   vEdit3
Gui Add, Button  , wp,  OK
Gui Add, Progress, w30  x+m ym cSilver vbar, 100
Gui Show,, Test
Return

GuiSize:
bottom := 0
WinGet cList, ControlList, % "ahk_id" hGui       ; Get list of GUI controls
For each, ctl in StrSplit(cList, "`n") {         ; Loop through controls
 GuiControlGet pos, Pos, % ctl                   ; Get control's position
 bottom := Max(bottom, posY + posH - 1)          ; Save the largest y-value for control's bottom edge
}
GuiControlGet barPos, Pos, bar                   ; Get the bar's position
GuiControl Move, bar, % "h" bottom - barPosY + 1 ; Adjust height to match bottom control
Return
image230822-0703-001_cr.png
Output
image230822-0703-001_cr.png (9.8 KiB) Viewed 386 times
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: How to calculate total height of controls

Post by m3user » 22 Aug 2023, 06:25

Thank you so much mikeyww, you did it again!
Post Reply

Return to “Ask for Help (v1)”