How to resize Picture Control in Gui to autofit Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
fatodubs
Posts: 29
Joined: 20 Sep 2017, 18:53

How to resize Picture Control in Gui to autofit

Post by fatodubs » 06 Feb 2023, 16:23

I'm trying to build a GUI to show an image and then wait for input. Sometimes the image will be portrait and other times landscape.

I am using two Picture controls - one that is hidden that I am using to get the size of the image, and the other one to at a size the fits the screen easily.

I'm struggling trying to resize the visible control to autosize. It doesn't work if I use the .Opt method, presumably because that's reserved for the Common properties. And if I use Move and set either the height or width to -1, it uses 0 and the image is not visible.

Code: Select all

	imgGui:=Gui("-SysMenu +Resize -MaximizeBox","Which way should this image be positioned?")
	imgGui.MarginX:=10
	imgGui.MarginY:=10
	guiPicTemp:=imgGui.AddPic("Hidden")
	guiPicShow:=imgGui.AddPic("xp yp h619 w-1")
	imgGui.Show("Hide w600 h600")
	Loop Files, fldrSrc . "\*.*" {
		guiPicTemp.Value:=A_LoopFileFullPath
		guiPicShow.Value:=A_LoopFileFullPath
		guiPicTemp.GetPos(&zxT, &zyT, &zwT, &zhT)
		imgGui.GetPos(&zxW, &zyW, &zwW, &zhW)
		If (zwT>zHT) {
			zwS:=zwW-20
			guiPicShow.Move(zxT,zyT,zwS,-1)
		} else {	
			zhS:=zhW-20
			guiPicShow.Move(zxT,zyT,-1,zhS)
		}
		guiPicShow.GetPos(&zxC, &zyC, &zwC, &zhC)
		imgGui.Show()
		Pause
	}

Is there any way to change the size of a picture control and have it autosize the remaining dimension, or am I going to need to calculate it each time?

fatodubs
Posts: 29
Joined: 20 Sep 2017, 18:53

Re: How to resize Picture Control in Gui to autofit  Topic is solved

Post by fatodubs » 06 Feb 2023, 16:33

My apologies...

I see that it needs to be set with the Value:

Code: Select all

If (zwT>zHT) {
	zwS:=zwW-20
	guiPicShow.Value:="*h-1 *w" . zwS . " " . A_LoopFileFullPath
} else {	
	zhS:=zhW-60
	guiPicShow.Value:="*w-1 *h" . zhS . " " . A_LoopFileFullPath
}

Post Reply

Return to “Ask for Help (v2)”